Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sudo yum install gcc krb5-devel
* `playbook` - Action to run [Ansible Playbook](http://docs.ansible.com/playbooks.html) (`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](http://docs.ansible.com/galaxy.html) - hub of [community developed roles](https://galaxy.ansible.com/) (`ansible-galaxy`).
* `galaxy.install` - Install role or collection from [Ansible Galaxy](http://docs.ansible.com/galaxy.html) - hub of [community developed roles](https://galaxy.ansible.com/) (`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).

Expand Down Expand Up @@ -69,10 +69,16 @@ st2 run ansible.vault.decrypt cwd=/etc/ansible vault_password_file=vault.txt fil
#### `ansible.galaxy` examples
```sh
# download many roles
st2 run ansible.galaxy.install roles='bennojoy.mysql kosssi.composer'
st2 run ansible.galaxy.install type=role roles='bennojoy.mysql kosssi.composer'

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

# download many collections
st2 run ansible.galaxy.install type=collection collections='microsoft.ad ansible.rabittmq'

# list collections
st2 run ansible.galaxy.list type=collection
```

## Tips & Tricks
Expand Down
9 changes: 8 additions & 1 deletion actions/ansible_galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ class AnsibleGalaxyRunner(AnsibleBaseRunner):
'--ignore_errors': '--ignore-errors',
'--no_deps': '--no-deps',
'--role_file': '--role-file',
'--collection_file': '-r',
'--collection_path': '--collection-path',
}

def __init__(self, *args, **kwargs):
super(AnsibleGalaxyRunner, self).__init__(*args, **kwargs)
tmpArgs = []
for arg in args[0]:
for item in arg.split(' '):
if item != "":
tmpArgs.append(item)
super(AnsibleGalaxyRunner, self).__init__(tmpArgs, **kwargs)


if __name__ == '__main__':
Expand Down
23 changes: 21 additions & 2 deletions actions/galaxy.install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,42 @@ parameters:
description: "Action timeout in seconds. Action will get killed if it doesn't finish in timeout seconds"
type: integer
default: 300
type:
description: "Install role(s) or collection(s)?"
type: string
enum:
- collection
- role
position: 0
default: role
action:
description: "Action to use"
type: string
position: 0
position: 1
default: install
immutable: true
roles:
description: "Role(s) to install (separated by space)"
type: string
position: 1
position: 2
default: ""
collections:
description: "Collection(s) to install (separated by space)"
type: string
position: 3
default: ""
ignore_errors:
description: "Ignore errors and continue with the next specified role [-i]"
type: boolean
no_deps:
description: "Don't download roles listed as dependencies [-n]"
type: boolean
collection_file:
description: "A file with list of collections to be installed. Note that role file can contain links to .git or .tar file [-r]"
type: string
collections_path:
description: "The path to the directory containing your collections. The default is the collections_path configured in your ansible.cfg file (/etc/ansible/collections if not configured) [-p]"
type: string
role_file:
description: "A file with list of roles to be installed. Note that role file can contain links to .git or .tar file [-r]"
type: string
Expand Down
13 changes: 13 additions & 0 deletions actions/lib/ansible_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,22 @@ def __init__(self, args):
:type args: ``list``
"""
self.args = args[1:]
self._parse_args() # move args starting with -- to the end of the command line
self._parse_extra_vars() # handle multiple entries in --extra_vars arg
self._prepend_venv_path()

def _parse_args(self):
"""
This method moves the args starting with -- to the end of the command line
It also deletes any empty args
"""
for i, arg in enumerate(self.args):
if arg.startswith("--"):
self.args.append(self.args[i]) # move to the end
del self.args[i] # delete original arg
elif arg == "":
del self.args[i] # delete the arg as it's empty

def _parse_extra_vars(self):
"""
This method turns the string list ("--extra_vars=[...]") passed in from the args
Expand Down