How can I write variables inside the tasks file in ansible?


I have this play.yml

My apache.yml file looks like this:

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.


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.


Use set_fact before your task to set facts which seem interchangeable with variables:

See for the official word.

Leave a Reply