Stuck deploying templated configs for multiple users with with_items

17 views
Skip to first unread message

Patrick Laimbock

unread,
Sep 1, 2016, 4:20:27 PM9/1/16
to ansible...@googlegroups.com
Hi,


I want to deploy a couple of OpenVPN configs to multiple users. It works
for a single user but now I'm stuck trying to make it work for multiple
users. Anyone have a suggestion how to make this work?

Variables:

---

openvpn_networks:
site1:
openvpn_config: site1-server1
site2:
openvpn_config: site2-server1

openvpn_users:
- name: patrick
base: /home/
- name: test
base: /home/


The task below works (apologies for the wrapping):

ansible/roles/openvpn/client/tasks/main.yml

---

- name: install openvpn NetworkManager client config(s)
template:
src: "{{ item }}/openvpn_networks[item].openvpn_config }}.j2"
dest: "/home/patrick/{{openvpn_networks[item].openvpn_config }}.ovpn"
mode: 0644
with_items:
- '{{ openvpn_networks | list }}'


But I can't figure out how to do this for multiple users as it fails
with: the field 'args' has an invalid value, which appears to include a
variable that is undefined. The error was: 'unicode object' has no
attribute 'base'

- name: install multi-user openvpn NetworkManager client config(s)
template:
src: "{{ item }}/{{ openvpn_networks[item].openvpn_config }}.j2"
dest: "{{ item.2.base }}/{{ item.2.name }}/test/{{
openvpn_networks[item].openvpn_config }}.ovpn"
owner: "{{ item.2.name }}"
group: "{{ item.2.name }}"
mode: 0644
with_items:
- '{{ openvpn_networks | list }}'
- '{{ openvpn_users }}'


How to make this work (possibly in a better way)?

Thanks a bunch!
Patrick

Kai Stian Olstad

unread,
Sep 1, 2016, 4:46:45 PM9/1/16
to ansible...@googlegroups.com
Are you trying to make all the users on all the sites?
If so, check out with_nested
https://docs.ansible.com/ansible/playbooks_loops.html#nested-loops

--
Kai Stian Olstad

Patrick Laimbock

unread,
Sep 1, 2016, 7:30:03 PM9/1/16
to ansible...@googlegroups.com
Hi Kai,

On 01-09-16 22:46, Kai Stian Olstad wrote:
>
> Are you trying to make all the users on all the sites?
> If so, check out with_nested
> https://docs.ansible.com/ansible/playbooks_loops.html#nested-loops

Thank you for your suggestion. That was the solution :) In #ansible
agaffney mentioned that with_nested couldn't handle looping over a dict.
So I changed the dict to a list and now it's working.

Thanks again,
Patrick
Reply all
Reply to author
Forward
0 new messages