Setting a variable just for a task

37 views
Skip to first unread message

Jim McMahon

unread,
Mar 5, 2015, 4:25:49 PM3/5/15
to ansible...@googlegroups.com
Is there a way to set a variable just for a task?  Say the task uses the template module and I want to set a variable just for that task that is not specific to the host I'm on.  

Mark McCoy

unread,
Mar 5, 2015, 5:47:44 PM3/5/15
to ansible-project
You should be able to put this variable in the rolename/defaults/main.yml file. This way there is a default value and if you do need to override it for a particular host or group you can do that easily.
On Thu, Mar 5, 2015 at 3:25 PM, Jim McMahon <jmcm...@flatworldknowledge.com> wrote:
Is there a way to set a variable just for a task?  Say the task uses the template module and I want to set a variable just for that task that is not specific to the host I'm on.  

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c0d7523f-82a2-4d54-9973-2aab67070d66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dag Wieers

unread,
Mar 5, 2015, 5:57:34 PM3/5/15
to ansible...@googlegroups.com
You can define a variable (conditionally) inside the template, or use
set_fact in the previous task, or include_vars in a previous task.

It depends on what you would like to achieve, and why.

--
Dag

Jim McMahon

unread,
Mar 8, 2015, 9:46:24 PM3/8/15
to ansible...@googlegroups.com
I thought about using the set_fact in the previous task. It just seems more natural to set it in the same task, but that’s not possible.

Thanks,

Jim
Reply all
Reply to author
Forward
0 new messages