# Example for running a playbook using Python API

**URL:** <https://forum.ansible.com/t/example-for-running-a-playbook-using-python-api/12413>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [February 23, 2013, 11:37pm UTC](https://forum.ansible.com/t/example-for-running-a-playbook-using-python-api/12413 "2013-02-23T23:37:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 23, 2013, 11:37pm UTC](https://forum.ansible.com/t/example-for-running-a-playbook-using-python-api/12413/1 "2013-02-23T23:37:52Z")

</div>

Probably the best example of running a playbook via Python code is  
actually /usr/bin/ansible-playbook itself, though it uses nearly all  
of the flags.

[https://github.com/ansible/ansible/blob/devel/bin/ansible-playbook](https://github.com/ansible/ansible/blob/devel/bin/ansible-playbook)

Anything referenced there either comes from command line flags or is  
constructed further up in that file.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Dat\_Dao](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Dat\_Dao](https://forum.ansible.com/u/Dat_Dao)\
**Post date:** [April 25, 2017, 5:27pm UTC](https://forum.ansible.com/t/example-for-running-a-playbook-using-python-api/12413/2 "2017-04-25T17:27:58Z")

</div>

Hi all,  
I have a Playbook which is used to push template configuration to the router, It work fine if I run command ansible-playbook playbook\_name.yml  
But now I don’t want call Playbook manually, I want to creat a file (such as pb.run) and then use it to call playbook.  
How I can do it?  
Please help me, thanks!

Vào 06:37:52 UTC+7 Chủ Nhật, ngày 24 tháng 2 năm 2013, Michael DeHaan đã viết:

---

<div class="post-metadata">

**Author:** ![balubhai555](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@balubhai555](https://forum.ansible.com/u/balubhai555)\
**Post date:** [April 25, 2017, 7:24pm UTC](https://forum.ansible.com/t/example-for-running-a-playbook-using-python-api/12413/3 "2017-04-25T19:24:27Z")

</div>

> > Hello Dao,

I did the same in ansible.

- I created one **pb.sh** within the file i wrote below

ansible-playbook playbook1.yml

and saved.

- then i change the permission **chmod +x pb.sh** and run those as  
**[root@localhost]# ./pb.sh**

i think it is useful to you also.

---

<div class="post-metadata">

**Author:** ![mantis\_quito](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@mantis\_quito](https://forum.ansible.com/u/mantis_quito)\
**Post date:** [February 5, 2020, 8:33am UTC](https://forum.ansible.com/t/example-for-running-a-playbook-using-python-api/12413/4 "2020-02-05T08:33:03Z")

</div>

[Ansible Training In Hyderabad](https://mantisquito.com/ansible-training-in-hyderabad-mastering-ansible/)
