V
V
Vadim2019-06-09 00:29:26
Ansible
Vadim, 2019-06-09 00:29:26

Is it possible to override a variable during playbook startup?

Hello everyone,
if in the vars subdirectory, from the directory where the playbooks are stored in the main.yml file, I set the phpversion variable: "7.0"
can I override it during the start of the playbook? For example ansible-playbook -e "phpversion=7.1" or will the version set in main.yml still be used?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Orlov, 2019-06-09
@Viji

Here is the order of precedence from lowest to highest (the last variables listed win in terms of priority):

  1. command line values ​​(eg “-u user”)
  2. role defaults [1]
  3. inventory file or script group vars [2]
  4. inventory group_vars/all [3]
  5. playbook group_vars/all [3]
  6. inventory group_vars/* [3]
  7. playbook group_vars/* [3]
  8. inventory file or script host vars [2]
  9. inventory host_vars/* [3]
  10. playbook host_vars/* [3]
  11. host facts / cached set_facts [4]
  12. play wars
  13. play vars_prompt
  14. play vars_files
  15. role vars (defined in role/vars/main.yml)
  16. block vars (only for tasks in block)
  17. task vars (only for the task)
  18. include_vars
  19. set_facts/registered vars
  20. role (and include_role) params
  21. include params
  22. extra vars (always win precedence)
Variable precedence: Where should I put a variable?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question