diff --git a/README.md b/README.md index 010e04f..deebe20 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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 diff --git a/actions/ansible_galaxy.py b/actions/ansible_galaxy.py index 17c403a..8eb798c 100755 --- a/actions/ansible_galaxy.py +++ b/actions/ansible_galaxy.py @@ -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__': diff --git a/actions/galaxy.install.yaml b/actions/galaxy.install.yaml index cdffbbb..0769beb 100644 --- a/actions/galaxy.install.yaml +++ b/actions/galaxy.install.yaml @@ -22,16 +22,29 @@ 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]" @@ -39,6 +52,12 @@ parameters: 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 diff --git a/actions/lib/ansible_base.py b/actions/lib/ansible_base.py index e56006e..de0e9e7 100644 --- a/actions/lib/ansible_base.py +++ b/actions/lib/ansible_base.py @@ -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