Hello,
So include and with_items is depricated and I am wondering how to implement the following:
I have to create a couple of similar services:
(I know this is not working)
`
- name: loopy
shell: download something
template: src: dest:
service: name={{ service }} state=started
with_items: listing
`
Is the only way to do this?
`
- name: download everything
shell: download something
with_items: listing
- name: copy templates
template: src: dest:
with_items: listing
- name: download everything
service: name={{ service }} state=started
with_items: listing
`
What would be a better approach?
thanks
Peter
The solution you’ve shown is the only one at the moment.
Peter Mooshammer pmoosha@gmail.com napisał:
thanks for getting back to me.
Here is what i intended:
I have a list of docker services:
`
services:
- servicename: zapp
containername: zapp
port: 5555
protocol: tcp
exposed: false
image: zapp
- servicename: xox
containername: xox
port: 4444
protocol: udp
exposed: true
linkto: zapp
image: xox
`
And I wanted to use a loop to create those services, but now I am doing this:
`
- { role: some-services, service: “{{ services[0] }}” }
- { role: some-services, service: “{{ services[1] }}” }
`
And I wanted to do this as a loop. But maybe I am completely off. Any ideas?
Note one of the reasons I am doing this is because ansible does not support docker restarts at the moment (it will with 1.9)
thanks
Peter
Brian_Coca
(Brian Coca)
4
there is not currently a way to loop through roles, you can make the
role accept a list and have it's tasks loop over it though.
also i would advice to not use a variable named 'service' as it can
conflict with the module of the same name.
I'm pretty sure modules and actions live in a different name space than variables. Or do you mean visually?
I think Tomasz it correct, it was working. Changed it anyways so people don’t get confused.
One more question. I tried:
And I wanted to use a loop to create those services, but now I am doing this:
`
- { role: some-services, service: “{{ services[0] }}”, when: services[0] is defined }
- { role: some-services, service: “{{ services[1] }}”, when: services[1] is defined }
`
or
`
- { role: some-services, service: “{{ services[0] }}”, when: “{{ services[0] }}” is defined }
- { role: some-services, service: “{{ services[1] }}”, when: “{{ services[0] }}” is defined }
`
But none of that is working, this however works:
`
- { role: some-services, service: “{{ services[1] }}”, when: simple_var is defined }
`
thanks
Peter
just an update:
`
- name: debug {{ services[0][‘hostname’] }}
debug: msg={{ services[0][‘hostname’] }}
when: services[0] is defined
- name: debug {{ services[3][‘hostname’] }}
debug: msg={{ services[3][‘hostname’] }}
when: services[3] is defined
`
This, it is just not working as a conditional for roles…