1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Added organization in the scm_credential get (#49884)

* Added organization in the scm_credential get

* Fallback looking for cred in project org

* Tests project with multi org credential

* Fixed CI issue

* Added changelog fragment
This commit is contained in:
Andrea Tartaglia 2018-12-19 12:01:12 +00:00 committed by John R Barker
parent afdd4e2343
commit 65c7424a35
3 changed files with 36 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "tower_project - getting project credential falls back to project organization if there's more than one cred with the same name"

View file

@ -146,7 +146,11 @@ def main():
if scm_credential:
try:
cred_res = tower_cli.get_resource('credential')
cred = cred_res.get(name=scm_credential)
try:
cred = cred_res.get(name=scm_credential)
except (tower_cli.exceptions.MultipleResults) as multi_res_excinfo:
module.warn('Multiple credentials found for {0}, falling back looking in project organization'.format(scm_credential))
cred = cred_res.get(name=scm_credential, organization=org['id'])
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)

View file

@ -47,3 +47,32 @@
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible
- name: "Create {{ item }}"
tower_organization:
name: "{{ item }}"
loop:
- TestOrg1
- TestOrg2
- name: "Create credential"
tower_credential:
kind: scm
name: TestCred1
organization: "{{ item }}"
loop:
- TestOrg2
- TestOrg1
- name: Create project TestProject
tower_project:
name: TestProject
organization: TestOrg1
scm_type: git
scm_url: "https://github.com/ansible/ansible"
scm_credential: TestCred1
register: multi_org_cred_project
- assert:
that:
- "multi_org_cred_project is changed"