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 (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”
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.