Try something like this:
{% for svr in groups.ntp_servers %}
{% if not svr == inventory_hostname %}
peer svr
{% endif %}
{% endfor %}
On Mon, Jul 14, 2014 at 4:30 AM, John Wang <[email protected]> wrote:
> I'm new to Ansible and want use it to configure a NTP service. here is my
> situation:
>
> my hosts file:
>
> [ntp_servers]
> s1.aaa.com
> s2.aaa.com
> s3.aaa.com
> s4.aaa.com
>
> The "/taskts/mail.yaml" for role "ntp_server":
>
> - name: install ntp
> apt: name=ntp state=present
> - name: config ntpd
> template: src=ntp.conf dest=/etc/ntp.conf
>
> The "templates/ntp.conf" for role "ntp_server":
>
> ...
> restrict {{ ntp_net }} mask {{ ntp_netmask }} nomodify notrap
> {% for svr in servers %}
> peer svr
> {% endfor %}
> ...
>
> My questions are about for loop in the template file (please leave along the
> NTP specific things):
>
> How to refer the hosts defined in the hosts file from within the template
> file? In another words, I need the value of "servers" variable in the for
> loop to be a list of "s1.aaa.com", "s2.aaa.com" ...
> How to know the current host so that the for loop could exclude it(it should
> not be peer to itself) ?
>
>
> Thanks and Regards
> John
>
>
>
> --
> 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/684a949d-05c9-4be7-8a66-0558f84a6979%40googlegroups.com.
> 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/CAJQqANfFg3x52z5jy622zgjW3%2BPFFvAapyW15Uwosp%2BK4_5W1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.