# Translate simple Ansible Playbook into Python

**URL:** <https://forum.ansible.com/t/translate-simple-ansible-playbook-into-python/25776>\
**Category:** Ansible Project\
**Created:** [October 19, 2017, 9:29am UTC](https://forum.ansible.com/t/translate-simple-ansible-playbook-into-python/25776 "2017-10-19T09:29:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Bartsch](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@Tom\_Bartsch](https://forum.ansible.com/u/Tom_Bartsch)\
**Post date:** [October 19, 2017, 9:29am UTC](https://forum.ansible.com/t/translate-simple-ansible-playbook-into-python/25776/1 "2017-10-19T09:29:24Z")

</div>

Hi there,

could someone translate me the following playbook into python language?

```auto
---
- 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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 19, 2017, 11:10am UTC](https://forum.ansible.com/t/translate-simple-ansible-playbook-into-python/25776/2 "2017-10-19T11:10:31Z")

</div>

> 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 }}"
> 
> &nbsp;&nbsp;vars:  
> &nbsp;&nbsp;&nbsp;&nbsp;static\_jobs:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- templatename: "template1"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;templateextension: "zip"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;templateversion: "1.0.0"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- templatename: "template2"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;templateextension: "zip"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;templateversion: "2.0.0"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- templatename: "template3"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;templateextension: "war"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;templateversion: "4.5.0"
> 
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;- name: will not start message  
> &nbsp;&nbsp;&nbsp;&nbsp;debug: "msg='{{ item.templatename }} und dann {{  
> item.templateextension }} und am Ende {{ item.templateversion }} ...'"  
> &nbsp;&nbsp;&nbsp;&nbsp;with\_items: "{{ static\_jobs }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;when: item.templateversion == "2.0.0"

static\_jobs = [  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{"templatename": "template1", "templateextension": "zip", "templateversion": "1.0.0"},  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{"templatename": "template2", "templateextension": "zip", "templateversion": "2.0.0"},  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{"templatename": "template3", "templateextension": "war", "templateversion": "4.5.0"}  
]

for item in static\_jobs:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if item["templateversion"] == "2.0.0":  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print item["templatename"] + " und dann " + item["templateextension"] + " und am Ende " + item["templateversion"] + "\n"

---

<div class="post-metadata">

**Author:** ![Tom\_Bartsch](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@Tom\_Bartsch](https://forum.ansible.com/u/Tom_Bartsch)\
**Post date:** [October 19, 2017, 2:19pm UTC](https://forum.ansible.com/t/translate-simple-ansible-playbook-into-python/25776/3 "2017-10-19T14:19:56Z")

</div>

Thank you very much.
