Hi Michael Ansible considers “yes” strings as True booleans but for comparison you can use the bool filter. Perhaps try something like this:
- debug: msg="run this task" when: elasticsearch_purge_old_indices_node|bool On 3 January 2015 at 00:09, Michael Liu <[email protected]> wrote: Hey All, > > I'm trying to force a task to run based on a host variable I've set. The > goal is to only have the task run (on a host) when the > "elasticsearch_purge_old_indices_node" variable is set to "yes". > > Inventory file: > > [elasticsearch] > elasticsearch1 elasticsearch_purge_old_indices_node=yes > elasticsearch2 > elasticsearch3 > > > Task: > > - name: add a nightly cronjob task to purge node > lineinfile: dest=/etc/crontab line="0 1 * * * * root /path/to/script.sh" > state=present > when: elasticsearch_purge_old_indices_node == "yes" > > > Error output: > TASK: [elasticsearch | cron job to purge old log indices] ************** > fatal: [elasticsearch1] => One or more undefined variables: 'dict object' > has no attribute 'address' > fatal: [elasticsearch2] => error while evaluating > conditional: elasticsearch_purge_old_indices_node == "yes" > fatal: [elasticsearch3] => error while evaluating > conditional: elasticsearch_purge_old_indices_node == "yes" > > > How do I force a task to run based on a host variable I've set? > > Thanks! > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/63f138f5-9447-4fbd-8cea-c368a7b1deb2%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/63f138f5-9447-4fbd-8cea-c368a7b1deb2%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAAnNz0MQ3ajWeWr9xPSftmL_HgeHX-E_1RGXL-U8rUzWfpvZcg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
