# Is it acceptable to call 'ansible-playbook' from an Ansible role?

**URL:** <https://forum.ansible.com/t/is-it-acceptable-to-call-ansible-playbook-from-an-ansible-role/27068>\
**Category:** Ansible Developer\
**Tags:** kubernetes\
**Created:** [March 21, 2018, 4:41pm UTC](https://forum.ansible.com/t/is-it-acceptable-to-call-ansible-playbook-from-an-ansible-role/27068 "2018-03-21T16:41:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhino](https://avatars.discourse-cdn.com/v4/letter/r/a5b964/32.png) [@rhino](https://forum.ansible.com/u/rhino)\
**Post date:** [March 21, 2018, 4:41pm UTC](https://forum.ansible.com/t/is-it-acceptable-to-call-ansible-playbook-from-an-ansible-role/27068/1 "2018-03-21T16:41:51Z")

</div>

I would like some other’s thoughts on calling ‘ansible-playbook’ from within an Ansible role - essentially calling Ansible from Ansible. It certainly looks strange…_but it works_. And I’m not sure of another way to go about it in my specific scenario. Is this “OK” to do? Or a big no-no? If its a no, then what’s the reasoning why? Is there a better way to achieve what I am trying to do?

Here’s my scenario…

I want to use an existing **collection of roles** (not a single role), that has its own playbook provided, and automate downloading and using it with Ansible (and do other things in addition to that). Because it is a collection of roles with a playbook I need to call, I cannot use “include\_role.”

More specifically, I want to automate the creation of a kubernetes cluster using Kubespray ([GitHub - kubernetes-sigs/kubespray: Deploy a Production Ready Kubernetes Cluster](https://github.com/kubernetes-incubator/kubespray)). Instead of instructing the user to manually download kubespray, manually unzip it, and manually run it, then finally run my role that does additional things, I’ve automated all of it via Ansible. Here’s what I’m doing:

`

- name: Downloading Kubespray  
get\_url:  
url: “[https://api.github.com/repos/kubernetes-incubator/kubespray/zipball/v2.4.0](https://api.github.com/repos/kubernetes-incubator/kubespray/zipball/v2.4.0)”  
dest: “~/.ansible/kubespray-2.4.0.zip”

- name: Extracting Kubespray  
unarchive:  
src: “~/.ansible/kubespray-2.4.0.zip”  
dest: “~/.ansible/”

#In this shell command, ‘cluster.yml’ is the playbook provided by kubespray

- name: Creating kubernetes cluster with Kubespray.  
shell: “ansible-playbook -i ~/.ansible/kubespray/inventory/hosts.ini ~/.ansible/kubespray/cluster.yml”  
register: ansible\_output

# Other things

# Other things

# etc, etc

`

Is this an acceptable approach? Certainly calling ansible from ansible seems odd, but it works.

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [March 22, 2018, 6:11pm UTC](https://forum.ansible.com/t/is-it-acceptable-to-call-ansible-playbook-from-an-ansible-role/27068/2 "2018-03-22T18:11:59Z")

</div>

I would consider it unusual, but it should work fine. Assuming there are no

expectations that the outer and inner ansible-playbook invocations are sharing

internal data or state.

See [https://image.slidesharecdn.com/moretipsntricks-161011152406/95/more-tips-n-tricks-24-638.jpg?cb=1476199481](https://image.slidesharecdn.com/moretipsntricks-161011152406/95/more-tips-n-tricks-24-638.jpg?cb=1476199481)

(slide 24 of [https://www.slideshare.net/bcoca/more-tips-n-tricks](https://www.slideshare.net/bcoca/more-tips-n-tricks))
