-
Notifications
You must be signed in to change notification settings - Fork 181
How to discover Ansible Playbooks using Salt
From the Uyuni/SUMA server:
We have few alternatives:
- Exploring a single path:
# salt my-ansible-control-node ansible.discover_playbooks /root/ansible-examples/
my-ansible-control-node:
----------
/root/ansible-examples/:
----------
jboss-standalone/demo-aws-launch.yml:
----------
custom_inventory:
/root/ansible-examples/jboss-standalone/hosts
fullpath:
/root/ansible-examples/jboss-standalone/demo-aws-launch.yml
jboss-standalone/deploy-application.yml:
----------
custom_inventory:
/root/ansible-examples/jboss-standalone/hosts
fullpath:
/root/ansible-examples/jboss-standalone/deploy-application.yml
...
- Passing multiple location (list of paths)
# salt my-ansible-control-node ansible.discover_playbooks locations='["/root/ansible-examples/", "/root/playbooks"]'
my-ansible-control-node:
----------
/root/ansible-examples/:
----------
jboss-standalone/demo-aws-launch.yml:
----------
custom_inventory:
/root/ansible-examples/jboss-standalone/hosts
fullpath:
/root/ansible-examples/jboss-standalone/demo-aws-launch.yml
jboss-standalone/deploy-application.yml:
----------
custom_inventory:
/root/ansible-examples/jboss-standalone/hosts
fullpath:
/root/ansible-examples/jboss-standalone/deploy-application.yml
...
/root/playbooks:
----------
example_playbook1/site.yml:
----------
custom_inventory:
/root/playbooks/example_playbook1/hosts
fullpath:
/root/playbooks/example_playbook1/site.yml
example_playbook2/site.yml:
----------
fullpath:
/root/playbooks/example_playbook2/site.yml
In both cases, you would get the list of the playbooks found, under each given path, containing fullpath
attribute and also custom_inventory
in case that the playbook comes with its own hosts
file.
:param playbook_extension: File extension of playbooks file to search for. Default: "yml"
:param hosts_filename: Filename of custom playbook inventory to search for. Default: "hosts"
:param syntax_check: Skip playbooks that do not pass "ansible-playbook --syntax-check" validation. Default: False
In this PR: https://github.com/uyuni-project/uyuni/pull/3563 I'm pushing a new SLS file that you can directly download here: https://raw.githubusercontent.com/uyuni-project/uyuni/master-add-new-ansible-sls/susemanager-utils/susemanager-sls/salt/ansible/runplaybook.sls
Since the PR is not yet merged, you can temporary take that SLS file and place it manually into your Uyuni/SUMA server at /usr/share/susemanager/salt/ansible/
directory.
There are few options:
- Without passing
inventory
as pillar to the SLS, it uses the default inventory at/etc/ansible/hosts
# salt my-ansible-control-node state.apply ansible.runplaybook pillar='{"playbook_path": "/root/ansible-examples/wordpress-nginx_rhel7/site.yml", "rundir": "/root/ansible-examples/wordpress-nginx_rhel7/"}'
- Passing custom inventory:
# salt my-ansible-control-node state.apply ansible.runplaybook pillar='{"playbook_path": "/root/ansible-examples/wordpress-nginx_rhel7/site.yml", "rundir": "/root/ansible-examples/wordpress-nginx_rhel7/", "inventory": "/root/ansible-examples/wordpress-nginx_rhel7/hosts"}'
NOTE: Passing rundir
is important here and required in order run the playbook properly. We should set rundir
as the path where the playbook is stored, so other custom playbook values are properly resolved by Ansible when running the playbook.