Ansible 2.0 python-api: How to load playbooks or Tasks from file?

49 views
Skip to first unread message

Reinhard Kugler

unread,
Feb 20, 2016, 11:35:15 AM2/20/16
to Ansible Project
Hi!

I would like to load Tasks or Playbooks from file.
I created a setup using http://docs.ansible.com/ansible/developing_api.html for ansible 2.0 python-api.

Aim is to have a File (instead of the dict) containing Ansible tasks and and run them via Play() and TaskQueueManager() - as stated in the following example.

task-file:

  tasks:
  - copy: src=files/foo dest=/tmp/foo owner=root group=root mode=0644
  - sysctl: name=net.ipv4.ip_forward value=1 state=present
  - apt: name=wget state=absent

I'm looking for something like this:

f = open('task_file','r')
play_source =  dict(
        name = "Ansible Play",
        hosts = '192.168.56.212',
        gather_facts = 'no',
        tasks = read_tasks_from_file(f.read())
    )

Is there a method or Class to do that?

Thank you!

- Reinhard


Ansible Version:
ansible 2.0.0.2

Environment:

docker python-2.7



Reply all
Reply to author
Forward
0 new messages