Skip to content
This repository has been archived by the owner on Sep 26, 2018. It is now read-only.

Latest commit

 

History

History

ansible

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Ansible Integration Pack

This pack provides Ansible integration to perform remote operations on both local and remote machines. After pack installation all ansible executable files are available in pack virtualenv and ready to use.

Actions

  • command - Run single Ad-Hoc command. It has all the regular parameters of ansible executable.
  • command_local - Perform single ansible Ad-Hoc command (module) locally.
  • playbook - Action to run Ansible Playbook (ansible-playbook executable).
  • vault.encrypt - Encrypt ansible data files (playbooks, vars, roles, etc) with password (ansible-vault executable).
  • vault.decrypt - Decrypt ansible data files (playbooks, vars, roles, etc) with password (ansible-vault executable).
  • galaxy.install - Install role from Ansible Galaxy - hub of community developed roles (ansible-galaxy).
  • galaxy.list - List installed from Ansible Galaxy roles (ansible-galaxy executable).
  • galaxy.remove - Remove the role installed from Ansible Galaxy (ansible-galaxy executable).

Examples

See StackStorm with Ansible on Vagrant demo for more examples

ansible.command examples

# run ansible command with optional verbose parameter
st2 run ansible.command hosts=all args='hostname -i' verbose=vv

Action ansible.command_local is helper for the ansible.command with predefined parameters to run the command locally. So this is the same:

st2 run ansible.command_local args='echo $TERM'
st2 run ansible.command connection=local inventory_file='127.0.0.1,' hosts=all args='echo $TERM'

which is equivalent of ansible commands:

ansible all -c local -i '127.0.0.1,' -a 'echo $TERM'
ansible all --connection=local --inventory-file='127.0.0.1,' --args='echo $TERM'

ansible.playbook examples

# run some simple playbook
st2 run ansible.playbook playbook=/etc/ansible/playbooks/nginx.yml

# run playbook on last machine listed in inventory file
st2 run ansible.playbook playbook=/etc/ansible/playbooks/nginx.yml limit='all[-1]'
Structured output
# get structured JSON output from a playbook
st2 run ansible.playbook playbook=/etc/ansible/playbooks/nginx.yml env='{"ANSIBLE_STDOUT_CALLBACK":"json"}'

Using the JSON stdout_callback leads to JSON output which enables access to details of the result of the playbook in actions following the playbook execution, e.g. posting the results to Slack in an action-alias.

format: | 
    *Execution Overview*
    {% for host, result in execution.result.stdout.stats.iteritems() %}
        {{ host }}: ```{{ result }}```
    {% endfor %}

There is, however, a bug that breaks the JSON when the playbook execution fails (example output below). See this issue for more information. Manual handling of this case is necessary until the bug is fixed.

	to retry, use: --limit @/etc/ansible/playbooks/top.retry
{
    "plays": [
        {
            "play": {
                "id": "b5fe7b50-9d7d-4927-ac17-6886218bcabc", 
                "name": "some-host.com"
            }, 
            ...
}

ansible.vault examples

# encrypt /tmp/nginx.yml playbook with password containing in vault.txt
st2 run ansible.vault.encrypt vault_password_file=vault.txt files=/tmp/nginx.yml

# decrypt /etc/ansible/nginx.yml and /etc/ansible/db.yml files
st2 run ansible.vault.decrypt cwd=/etc/ansible vault_password_file=vault.txt files='nginx.yml db.yml'

# decrypt all files in /etc/ansible/playbooks directory
st2 run ansible.vault.decrypt cwd=/etc/ansible vault_password_file=vault.txt files='playbooks/*'

ansible.galaxy examples

# download many roles
st2 run ansible.galaxy.install roles='bennojoy.mysql kosssi.composer'

# list rolex
st2 run ansible.galaxy.list roles_path=/etc/ansible/roles