Is it possible to override a variable during startup playbook?

Hi all,

if the vars subdirectory, from the directory where playbooks are stored in the main file.yml I ask peremennoy phpversion: "7.0"

can I override it during start-up playbook? For example ansible-playbook -e "phpversion=7.1" or still will use the version specified in the main.yml?
March 23rd 20 at 19:41
2 answers
March 23rd 20 at 19:43
Solution
Yes, you can... you can still like ansible-playbook --extra-vars "phpversion=7.1"

That sub in the command line will have priority
March 23rd 20 at 19:45
Solution
Here is the order of precedence from lowest to highest (last listed variables win by 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 vars
  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?

Find more questions by tags Ansible