Skip to content

Commit 72cd7b8

Browse files
committed
feat(awx): git credential helper
when used with awx, places credentials in ~/gitconfig !37
1 parent 1b8b7cb commit 72cd7b8

File tree

2 files changed

+19
-37
lines changed

2 files changed

+19
-37
lines changed

docs/projects/ansible/playbooks/awx.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Items supported for configuration:
2727
!!! note Info
2828
This playbook adds items ONLY. maybe in the future it will remove items no longer within the project. Merge requests welcome.
2929

30+
!!! tip
31+
Cloning a repository that requires credentials is possible if you put credentials in your `~/.gitconfig` file. If your using Ansible Automation Platform / AWX on playbook import a custom Git credential will be created that will setup the `~/.gitconfig` file, that you can use in job templates.
32+
3033

3134
## Playbook AWX / Tower / Automation Platform Template import
3235

tasks/awx/project.yaml

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,45 +46,24 @@
4646
loop_var: nfc_pb_awx_inventory
4747

4848

49-
# - name: GIT Checkout Project
50-
# ansible.builtin.git:
51-
# repo: "{{ nfc_pb_awx_project.scm_url }}"
52-
# dest: /tmp/project
53-
# # separate_git_dir: /tmp/project
54-
# # clone: true
55-
# # depth: 1
56-
# version: "{{ nfc_pb_awx_project.scm_branch | default('master') }}"
57-
# # single_branch: true
58-
# when: >
59-
# nfc_pb_awx_project.scm_url | default('') != ''
60-
# and
61-
# nfc_pb_awx_project.type | lower == 'playbook'
49+
- name: "[helper] Setup Git credentials if present"
50+
ansible.builtin.shell:
51+
cmd: |
52+
cat {{ tower.filename.git_credential_file }} > ~/.gitconfig;
53+
chmod 700 ~/.gitconfig;
54+
chown $(whoami):$(whoami) ~/.gitconfig;
55+
creates: ~/.gitconfig
56+
become: true
57+
when: tower.filename.git_credential_file is defined
6258

6359
- name: GIT Checkout Project
64-
ansible.builtin.command:
65-
cmd: |-
66-
git clone --depth 1 -b {{ nfc_pb_awx_project.scm_branch | default('master') }} https://
67-
{%- if nfc_pb_git_username is defined -%}
68-
{{ nfc_pb_git_username }}:{{ nfc_pb_git_token }}@
69-
{%- endif -%}
70-
{{- nfc_pb_awx_project.scm_url | replace('https://', '') }} /tmp/project
71-
# repo: "{{ nfc_pb_awx_project.scm_url }}"
72-
# dest: /tmp/project
73-
# # separate_git_dir: /tmp/project
74-
# # clone: true
75-
# # depth: 1
76-
# version: "{{ nfc_pb_awx_project.scm_branch | default('master') }}"
77-
# # single_branch: true
78-
no_log: true # Contains credentials.
79-
when: nfc_pb_awx_project.playbook_path is defined
80-
81-
82-
- name: GIT Init Submodule
83-
ansible.builtin.command:
84-
cmd: git submodule update --init
85-
chdir: /tmp/project
86-
no_log: true # Contains credentials.
87-
when: nfc_pb_awx_project.playbook_path is defined
60+
ansible.builtin.git:
61+
repo: "{{ nfc_pb_awx_project.scm_url }}"
62+
dest: /tmp/project
63+
version: "{{ nfc_pb_awx_project.scm_branch | default('master') }}"
64+
single_branch: true
65+
when: >
66+
nfc_pb_awx_project.playbook_path is defined
8867
8968
9069
- name: Add Job templates

0 commit comments

Comments
 (0)