Debian Codegraph @

test/integration/targets/ansible-galaxy-role/tasks/git-config-injection.yml

raw
1 - vars:
2 invalid_git_opts: '-ccore.sshCommand=sh -c "id > {{ remote_tmp_dir }}/role_exe"'
3 # use SSH protocol to test core.sshCommand is not configured
4 dummy_repo: [email protected]:ansible/nosuchrepo.git
5 block:
6 - name: Ensure git is installed
7 package:
8 name: git
9 when: ansible_distribution not in ["MacOSX", "Alpine"]
10 register: git_install
11
12 - name: Create invalid requirements file
13 copy:
14 dest: "{{ remote_tmp_dir }}/invalid-requirements.yml"
15 content: |
16 - src: {{ invalid_git_opts }}
17 scm: git
18 name: {{ dummy_repo }}
19 - src: {{ dummy_repo }}
20 scm: git
21 name: {{ invalid_git_opts }}
22
23 - name: Attempt to install invalid role requirements
24 command: ansible-galaxy install -r {{ remote_tmp_dir }}/invalid-requirements.yml --ignore-errors
25 register: result
26 environment:
27 ANSIBLE_NOCOLOR: True
28 ANSIBLE_FORCE_COLOR: False
29
30 - name: Validate git core.sshCommand did not run
31 stat:
32 path: "{{ remote_tmp_dir }}/role_exe"
33 register: stat_result
34 failed_when: stat_result.stat.exists
35
36 - name: Verify the invalid field is treated as a single positional argument (repo or dest)
37 assert:
38 that:
39 - stderr is search(error1)
40 - stderr is search(error2)
41 - (stderr | regex_findall("git clone") | length) == (stderr | regex_findall("git clone --") | length) == 2
42 vars:
43 stderr: "{{ result.stderr | regex_replace('\\n', ' ') }}"
44 error1: "repository '{{ invalid_git_opts }}' does not exist"
45 error2: "Cloning into '{{ invalid_git_opts }}'"
46
47 always:
48 - name: Uninstall git if it was installed
49 package:
50 name: git
51 state: absent
52 when: git_install is changed | default(false)