Thanks, it's good for me!

On Wed, Feb 11, 2015 at 12:10 AM, Chip Selden <[email protected]> wrote:

> Alexey,
>
> The easiest way to do this is to use hostvars in your inventory and set a
> "role" variable for each host. Then, in your task you could be:
>
> tasks:
> - name: Task
>   command: "/usr/bin/somecommand"
>   when: role == "upstream"
>
> Alternatively, if you want to set the variables here, this would work
> (tested):
>
> ---
> - name: Playbook
>   hosts: all
>   vars:
>     servers:
>       "192.168.122.12": "upstream"
>       "192.168.122.13": "downstream"
>       "192.168.122.14": "downstream"
>   tasks:
>   - name: Task
>     command: "/usr/bin/somecommand"
>     when: servers[ansible_default_ipv4.address] == "upstream"
>
> This evaluates the ip address of whatever host is being used and evaluates
> the correct variable inside the "servers" hash. There are other ways to
> organize the variables, and it isn't best practice to have numbers as
> variable names, but it works!
>
> \Chip
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/2zsWMmMCCuc/unsubscribe.
> To unsubscribe from this group and all its topics, 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/fa7276fe-b8fa-416a-abe5-6e3a9540b247%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/fa7276fe-b8fa-416a-abe5-6e3a9540b247%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/CAGnetYeOjxr0nESWhC4g4jxXWrcG8DNm28vQnh1YrmmMT0g5tg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to