From 934500fb055d411f619f6c6c5840547852c6a97c Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Tue, 24 Jul 2018 11:18:50 -0400 Subject: [PATCH] Properly detect credentials for tower_project It seemed like it was mostly the wrong variables been looked at, making it so a git repository could not be created without a credential. --- .../web_infrastructure/ansible_tower/tower_project.py | 6 +++--- test/integration/targets/tower_project/tasks/main.yml | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py index f59949d5599..d9d747aa943 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py @@ -147,18 +147,18 @@ def main(): except (exc.NotFound) as excinfo: module.fail_json(msg='Failed to update project, organization not found: {0}'.format(organization), changed=False) - if scm_type: + if scm_credential: try: cred_res = tower_cli.get_resource('credential') cred = cred_res.get(name=scm_credential) + scm_credential = cred['id'] except (exc.NotFound) as excinfo: module.fail_json(msg='Failed to update project, credential not found: {0}'.format(scm_credential), changed=False) - credential = cred['id'] if scm_type else None result = project.modify(name=name, description=description, organization=org['id'], scm_type=scm_type, scm_url=scm_url, local_path=local_path, - scm_branch=scm_branch, scm_clean=scm_clean, credential=credential, + scm_branch=scm_branch, scm_clean=scm_clean, credential=scm_credential, scm_delete_on_update=scm_delete_on_update, scm_update_on_launch=scm_update_on_launch, create_on_missing=True) diff --git a/test/integration/targets/tower_project/tasks/main.yml b/test/integration/targets/tower_project/tasks/main.yml index 116cf967d1a..ba79ebb50e4 100644 --- a/test/integration/targets/tower_project/tasks/main.yml +++ b/test/integration/targets/tower_project/tasks/main.yml @@ -40,3 +40,10 @@ - assert: that: - "result is changed" + +- name: Create a git project without credentials + tower_project: + name: git project + organization: Default + scm_type: git + scm_url: https://github.com/ansible/ansible