Interview Prep/Ansible/Variables, Facts and Precedence

Which magic variables are most useful?

IntermediateConceptVariables, Facts and Precedence
Answer
  • inventory_hostname, inventory_hostname_short
  • hostvars — all variables of every host in the inventory
  • groups — dict of group name to list of hosts
  • group_names — groups the current host is in
  • ansible_play_hosts, ansible_play_batch — hosts in the play / current serial batch
  • ansible_check_mode, ansible_diff_mode, ansible_version
  • playbook_dir, role_path, ansible_run_tags
- debug: msg="{{ groups['db'] | length }} database hosts"
All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence