Hi Matt,

Thanks for the with_items variable, but can this looping system be used to 
scan for hosts deep inside the inventory file rather than groups  (a child 
group? )
admin-1/2 are hosts here. I am using Ansible 2.4

Eg:

[admin:children]
admin-1
admin-2

I did try with the below syntax, but it didn't work. I think Ansible didn't 
like it either.

- -A INPUT -s "{{ hostvars[ my_platform + my_server + 
[item]]['ansible_ssh_host'] }}" -j ACCEPT
with_items: groups['admin:children']


Regards
VK

On Friday, 15 August 2014 00:05:16 UTC+1, Matt Martz wrote:
>
> I think what you want is the following:
>
> ---
> - name: Allow eth1 port 5432 access to Web servers
>   ufw: rule=allow interface=eth1 direction=in port=5432 proto=tcp src="{{
>  hostvars[item]['ansible_eth1']['ipv4']['address'] }}"
>   with_items: groups['webservers']
>
> That will loop over groups['webservers'] making item be an individual host 
> in the group, then you can just grab what you need from hostvars.
>
>
> On Thu, Aug 14, 2014 at 4:16 PM, Abe Voelker <[email protected]> wrote:
>
>> I have an inventory file like this:
>>
>> [webservers]
>> 10.0.0.1
>> 10.0.0.2
>> 10.0.0.3
>>
>> [postgresservers]
>> 10.0.0.4
>>
>> And I'm trying to run this playbook against my Postgres host:
>>
>> ---
>> - name: Allow eth1 port 5432 access to Web servers
>>   ufw: rule=allow interface=eth1 direction=in port=5432 proto=tcp src={{ 
>> item }}
>>   with_items:
>>     {% for host in groups['webservers'] %}
>>       - "{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}"
>>     {% endfor %}
>>
>> What I'm trying to accomplish is for the playbook to determine each Web 
>> host's eth1 IPv4 address (which is different from the eth0 IPv4 address 
>> listed in the inventory file) and add allowances for them in the Postgres 
>> host's firewall.
>>
>> However, my syntax is incorrect (sorry, I'm a Python noob):
>>
>> ERROR: Syntax Error while loading YAML script, 
>> /tmp/ansible/roles/postgres/tasks/firewall.yml
>> Note: The error may actually appear before this position: line 5, column 6
>>
>>
>>   with_items:
>>     {% for host in groups['web_servers'] %}
>>      ^
>>
>> Am I taking the right approach here and just need to fix my syntax, or is 
>> there a better way?
>>
>> Thanks!
>> Abe
>>
>> -- 
>> 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/6bbb9367-d0ac-4931-adb9-471d86266be8%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/6bbb9367-d0ac-4931-adb9-471d86266be8%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Matt Martz
> [email protected]
> http://sivel.net/ 
>

-- 
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/38858442-3466-4876-944b-36c06d47b625%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to