(NOOB) How to assign an array to a variabel in an Ansible-Playbook

85 views
Skip to first unread message

Benjamin Bauer

unread,
Jul 17, 2014, 4:59:27 AM7/17/14
to ansible...@googlegroups.com

Michael DeHaan

unread,
Jul 17, 2014, 8:35:52 AM7/17/14
to ansible...@googlegroups.com
If you're going to reask questions from Stack Overflow please paste the question here and save us the click.

We're not going to answer over on StackOverflow.

It's also much better to just ask here as you'll get quicker answers - much larger audience reading things.

I'm also unclear what you are having problems with so maybe you can elaborate a bit.

Thanks!


On Thu, Jul 17, 2014 at 4:59 AM, Benjamin Bauer <benjami...@gmail.com> wrote:

--
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/904bbe9d-fd30-480e-8937-c5080309123b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Benjamin Bauer

unread,
Jul 18, 2014, 4:04:05 AM7/18/14
to ansible...@googlegroups.com
I have a DB Server and a bunch of webservers (also running the application as of now). All the servers are connected via private networking on eth1. Now I need to configure postgresql (I am using the role Ansibles.postgresql) to accept password authenticated requests on eth1. The way to do this in Ansibles.postgresql role is to set value of variable to an array containing all the IPs of hosts that should be allowed to auth like so:

postgresql_pg_hba_passwd_hosts: ['10.129.181.241/32', 'my_other_ip', ...]

What I need to do now is to figure out a (the best) way to assign all the IPs on eht1 of all the servers in the group web to this variable and suffix them all with "/32"

I know I can get the IPs via
{% for host in groups['web'] %}
   
{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}
{% endfor %}


But this only works in a template, right? (Since jinja2 is not interpreted in playbookfiles?)

So I am looking for a complete answer of how to best achieve this in a most (Ansible-)standard way. I am sure this is a fairly common task, but right now I just can't see it.

Michael DeHaan

unread,
Jul 18, 2014, 7:47:11 AM7/18/14
to ansible...@googlegroups.com
Can I ask why you think you can't just template the postgresql security file?




Benjamin Bauer

unread,
Jul 18, 2014, 12:10:59 PM7/18/14
to ansible...@googlegroups.com

I try to use as many roles from galaxy as possible. Doing my own template just to solve this problem seems not like the best solution to me. The role works perfect for me otherwise.

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/HRsvNyY6DtI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

Michael DeHaan

unread,
Jul 18, 2014, 2:13:45 PM7/18/14
to ansible...@googlegroups.com
You will need to template the file and may need to customize an existing role then.

Galaxy is full of great examples and starting points, but it not meant to be 100% turnkey.



Benjamin Bauer

unread,
Jul 18, 2014, 6:08:05 PM7/18/14
to ansible...@googlegroups.com
OK, thanks a lot!

I wanted to ask a followup question, but it was so far off topic that I decided to open a new topic for it.
Reply all
Reply to author
Forward
0 new messages