From af238be377221fb34a99ffc4fddc1baf0c34dda4 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Thu, 10 Sep 2020 10:31:46 -0400 Subject: [PATCH] address a few follow-up issues for Org -> Galaxy Credentials support - add support for managing galaxy creds in the tower organization module - fix a minor serializer bug --- awx/api/serializers.py | 1 + .../plugins/modules/tower_organization.py | 20 +++++++++++++++++++ .../targets/tower_organization/tasks/main.yml | 2 ++ 3 files changed, 23 insertions(+) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 1299ba7aee..4800123757 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -2695,6 +2695,7 @@ class CredentialSerializerCreate(CredentialSerializer): attrs['organization'] = attrs['team'].organization if ( + 'credential_type' in attrs and attrs['credential_type'].kind == 'galaxy' and list(owner_fields) != ['organization'] ): diff --git a/awx_collection/plugins/modules/tower_organization.py b/awx_collection/plugins/modules/tower_organization.py index 5042ecf22c..0402056bbf 100644 --- a/awx_collection/plugins/modules/tower_organization.py +++ b/awx_collection/plugins/modules/tower_organization.py @@ -67,6 +67,11 @@ options: - list of notifications to send on start type: list elements: str + galaxy_credentials: + description: + - list of Ansible Galaxy credentials to associate to the organization + type: list + elements: str extends_documentation_fragment: awx.awx.auth ''' @@ -86,6 +91,14 @@ EXAMPLES = ''' custom_virtualenv: "/var/lib/awx/venv/foo-venv/" state: present tower_config_file: "~/tower_cli.cfg" + +- name: Create tower organization that pulls content from galaxy.ansible.com + tower_organization: + name: "Foo" + state: present + galaxy_credentials: + - Ansible Galaxy + tower_config_file: "~/tower_cli.cfg" ''' from ..module_utils.tower_api import TowerAPIModule @@ -102,6 +115,7 @@ def main(): notification_templates_success=dict(type="list", elements='str'), notification_templates_error=dict(type="list", elements='str'), notification_templates_approvals=dict(type="list", elements='str'), + galaxy_credentials=dict(type="list", elements='str'), state=dict(choices=['present', 'absent'], default='present'), ) @@ -149,6 +163,12 @@ def main(): for item in notifications_approval: association_fields['notification_templates_approvals'].append(module.resolve_name_to_id('notification_templates', item)) + galaxy_credentials = module.params.get('galaxy_credentials') + if galaxy_credentials is not None: + association_fields['galaxy_credentials'] = [] + for item in galaxy_credentials: + association_fields['galaxy_credentials'].append(module.resolve_name_to_id('credentials', item)) + # Create the data that gets sent for create and update org_fields = {'name': module.get_item_name(organization) if organization else name} if description is not None: diff --git a/awx_collection/tests/integration/targets/tower_organization/tasks/main.yml b/awx_collection/tests/integration/targets/tower_organization/tasks/main.yml index cc40ed59a7..d6b174f674 100644 --- a/awx_collection/tests/integration/targets/tower_organization/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_organization/tasks/main.yml @@ -12,6 +12,8 @@ - name: "Create a new organization" tower_organization: name: "{{ org_name }}" + galaxy_credentials: + - Ansible Galaxy register: result - assert: