From f5ee2a38fdb7c77f4ba4acaa02dbb1539fb67a3b Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Wed, 7 Aug 2024 21:03:28 +0100 Subject: [PATCH 01/11] Update galaxy.install.yaml --- actions/galaxy.install.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/actions/galaxy.install.yaml b/actions/galaxy.install.yaml index cdffbbb..92592ec 100644 --- a/actions/galaxy.install.yaml +++ b/actions/galaxy.install.yaml @@ -33,12 +33,22 @@ parameters: type: string position: 1 default: "" + collections: + description: "Collection(s) to install (separated by space)" + type: string + 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 From 5e9f1ec8b69ccad0a6cbb55b65c51534540b326c Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:22:07 +0100 Subject: [PATCH 02/11] Update ansible_galaxy.py --- actions/ansible_galaxy.py | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/ansible_galaxy.py b/actions/ansible_galaxy.py index 17c403a..7a66294 100755 --- a/actions/ansible_galaxy.py +++ b/actions/ansible_galaxy.py @@ -19,6 +19,7 @@ class AnsibleGalaxyRunner(AnsibleBaseRunner): '--ignore_errors': '--ignore-errors', '--no_deps': '--no-deps', '--role_file': '--role-file', + '--collection_file': '-r', } def __init__(self, *args, **kwargs): From aa0c4c63a2a14e6b17a6ccc509ed841140b8b50e Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:34:03 +0100 Subject: [PATCH 03/11] Update galaxy.install.yaml --- actions/galaxy.install.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/galaxy.install.yaml b/actions/galaxy.install.yaml index 92592ec..aaf6b9e 100644 --- a/actions/galaxy.install.yaml +++ b/actions/galaxy.install.yaml @@ -36,6 +36,7 @@ parameters: collections: description: "Collection(s) to install (separated by space)" type: string + position: 1 default: "" ignore_errors: description: "Ignore errors and continue with the next specified role [-i]" From 430702d7dddcd16a3e7348dbf50e01b85e50022d Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:11:29 +0100 Subject: [PATCH 04/11] Update galaxy.install.yaml --- actions/galaxy.install.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/actions/galaxy.install.yaml b/actions/galaxy.install.yaml index aaf6b9e..0769beb 100644 --- a/actions/galaxy.install.yaml +++ b/actions/galaxy.install.yaml @@ -22,21 +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: 1 + position: 3 default: "" ignore_errors: description: "Ignore errors and continue with the next specified role [-i]" From 1762cae56dc16b12cdf2c4217305f203fd30fa3b Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Sun, 11 Aug 2024 07:23:17 +0100 Subject: [PATCH 05/11] Update ansible_base.py --- actions/lib/ansible_base.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/actions/lib/ansible_base.py b/actions/lib/ansible_base.py index e56006e..aeda757 100644 --- a/actions/lib/ansible_base.py +++ b/actions/lib/ansible_base.py @@ -25,9 +25,18 @@ def __init__(self, args): :type args: ``list`` """ self.args = args[1:] + self._parse_args() self._parse_extra_vars() # handle multiple entries in --extra_vars arg self._prepend_venv_path() + def _parse_args(self): + for i, arg in enumerate(self.args): + if '--' in arg: + self.args.append(kv_param) # 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 From 7e9a4ad5277b67b1d428f8d6e42fdebd70782c62 Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Sun, 11 Aug 2024 07:25:06 +0100 Subject: [PATCH 06/11] Update ansible_galaxy.py --- actions/ansible_galaxy.py | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/ansible_galaxy.py b/actions/ansible_galaxy.py index 7a66294..2596cdd 100755 --- a/actions/ansible_galaxy.py +++ b/actions/ansible_galaxy.py @@ -20,6 +20,7 @@ class AnsibleGalaxyRunner(AnsibleBaseRunner): '--no_deps': '--no-deps', '--role_file': '--role-file', '--collection_file': '-r', + '--collection_path': '--collection-path', } def __init__(self, *args, **kwargs): From 8349a705161c40f7d80627bc9a30dbaa01d236b6 Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Sun, 11 Aug 2024 07:29:20 +0100 Subject: [PATCH 07/11] Update README.md --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 010e04f..59174ea 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=role collections='microsoft.ad ansible.rabittmq' + +# list collections +st2 run ansible.galaxy.list type=collection ``` ## Tips & Tricks From 9c99865db82768955df3111f8adecd7aa4f30504 Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Sun, 11 Aug 2024 07:37:51 +0100 Subject: [PATCH 08/11] Update ansible_base.py --- actions/lib/ansible_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/lib/ansible_base.py b/actions/lib/ansible_base.py index aeda757..dfafa88 100644 --- a/actions/lib/ansible_base.py +++ b/actions/lib/ansible_base.py @@ -32,7 +32,7 @@ def __init__(self, args): def _parse_args(self): for i, arg in enumerate(self.args): if '--' in arg: - self.args.append(kv_param) # move to the end + 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 From 71f2c38a81a501f7dc9c4fdaf89dbceceb465ec6 Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Sun, 11 Aug 2024 07:43:15 +0100 Subject: [PATCH 09/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 59174ea..deebe20 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ st2 run ansible.galaxy.install type=role roles='bennojoy.mysql kosssi.composer' st2 run ansible.galaxy.list type=role roles_path=/etc/ansible/roles # download many collections -st2 run ansible.galaxy.install type=role collections='microsoft.ad ansible.rabittmq' +st2 run ansible.galaxy.install type=collection collections='microsoft.ad ansible.rabittmq' # list collections st2 run ansible.galaxy.list type=collection From e28003033414fee82b7157ce593bcbbf04f40fd6 Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Sat, 7 Sep 2024 09:42:48 +0100 Subject: [PATCH 10/11] Update ansible_base.py --- actions/lib/ansible_base.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/actions/lib/ansible_base.py b/actions/lib/ansible_base.py index dfafa88..de0e9e7 100644 --- a/actions/lib/ansible_base.py +++ b/actions/lib/ansible_base.py @@ -25,13 +25,17 @@ def __init__(self, args): :type args: ``list`` """ self.args = args[1:] - self._parse_args() + 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 '--' in arg: + if arg.startswith("--"): self.args.append(self.args[i]) # move to the end del self.args[i] # delete original arg elif arg == "": From 90fcadb6722aec9a43232bb6182dc3f1dc2be753 Mon Sep 17 00:00:00 2001 From: jodygilbert <74103313+jodygilbert@users.noreply.github.com> Date: Sat, 7 Sep 2024 09:44:33 +0100 Subject: [PATCH 11/11] Update ansible_galaxy.py --- actions/ansible_galaxy.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/actions/ansible_galaxy.py b/actions/ansible_galaxy.py index 2596cdd..8eb798c 100755 --- a/actions/ansible_galaxy.py +++ b/actions/ansible_galaxy.py @@ -24,7 +24,12 @@ class AnsibleGalaxyRunner(AnsibleBaseRunner): } 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__':