Translate simple Ansible Playbook into Python

28 views
Skip to first unread message

Tom Bartsch

unread,
Oct 19, 2017, 5:29:24 AM10/19/17
to Ansible Project
Hi there,

could someone translate me the following playbook into python language?

---
- hosts: "{{ host }}"

vars:
static_jobs:
- templatename: "template1"
templateextension: "zip"
templateversion: "1.0.0"
- templatename: "template2"
templateextension: "zip"
templateversion: "2.0.0"
- templatename: "template3"
templateextension: "war"
templateversion: "4.5.0"

tasks:
- name: will not start message
debug: "msg='{{ item.templatename }} und dann {{ item.templateextension }} und am Ende {{ item.templateversion }} ...'"
with_items: "{{ static_jobs }}"
when: item.templateversion == "2.0.0"


Regards,
Tom

Kai Stian Olstad

unread,
Oct 19, 2017, 7:10:47 AM10/19/17
to ansible...@googlegroups.com
On 19.10.2017 11:29, 'Tom Bartsch' via Ansible Project wrote:
> Hi there,
>
> could someone translate me the following playbook into python language?

I don't understand why you would need that, it's just a loop that print
thing out the the condition are met.
But since I'm in a process to learn Python why not.


> ---
> - hosts: "{{ host }}"
>
> vars:
> static_jobs:
> - templatename: "template1"
> templateextension: "zip"
> templateversion: "1.0.0"
> - templatename: "template2"
> templateextension: "zip"
> templateversion: "2.0.0"
> - templatename: "template3"
> templateextension: "war"
> templateversion: "4.5.0"
>
> tasks:
> - name: will not start message
> debug: "msg='{{ item.templatename }} und dann {{
> item.templateextension }} und am Ende {{ item.templateversion }} ...'"
> with_items: "{{ static_jobs }}"
> when: item.templateversion == "2.0.0"
>

static_jobs = [
{"templatename": "template1", "templateextension": "zip",
"templateversion": "1.0.0"},
{"templatename": "template2", "templateextension": "zip",
"templateversion": "2.0.0"},
{"templatename": "template3", "templateextension": "war",
"templateversion": "4.5.0"}
]

for item in static_jobs:
if item["templateversion"] == "2.0.0":
print item["templatename"] + " und dann " +
item["templateextension"] + " und am Ende " + item["templateversion"] +
"\n"

--
Kai Stian Olstad

Tom Bartsch

unread,
Oct 19, 2017, 10:19:56 AM10/19/17
to Ansible Project
Thank you very much.
Reply all
Reply to author
Forward
0 new messages