Question:
I have this play.yml
1 2 3 4 5 6 |
--- - hosts: localhost tasks: - include: apache.yml |
My apache.yml file looks like this:
1 2 3 4 5 6 |
vars: url: http://example.com/apache - name: Download apache shell: wget {{ url }} |
This is giving me an error.
If I remove vars
then it works. But, I want to keep the variable inside the included tasks file, so that I can keep different variables for different tasks separate.
Answer:
NOTE: Using set_fact
as described below sets a fact/variable onto the remote servers that the task is running against. This fact/variable will then persist across subsequent tasks for the entire duration of your playbook.
Also, these facts are immutable (for the duration of the playbook), and cannot be changed once set.
ORIGINAL ANSWER
Use set_fact
before your task to set facts which seem interchangeable with variables:
1 2 3 4 5 6 7 |
- name: Set Apache URL set_fact: apache_url: 'http://example.com/apache' - name: Download Apache shell: wget {{ apache_url }} |
See http://docs.ansible.com/set_fact_module.html for the official word.