summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-galaxy-collection/tasks/list.yml
blob: b8d63492c6ba76d9460fa8e23babb5c4be8a0e3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
- name: initialize collection structure
  command: ansible-galaxy collection init {{ item }} --init-path "{{ galaxy_dir }}/dev/ansible_collections" {{ galaxy_verbosity }}
  loop:
    - 'dev.collection1'
    - 'dev.collection2'
    - 'dev.collection3'
    - 'dev.collection4'
    - 'dev.collection5'
    - 'dev.collection6'

- name: replace the default version of the collections
  lineinfile:
    path: "{{ galaxy_dir }}/dev/ansible_collections/dev/{{ item.name }}/galaxy.yml"
    line: "{{ item.version }}"
    regexp: "version: .*"
  loop:
    - name: "collection1"
      version: "version: null"
    - name: "collection2"
      version: "version: placeholder"
    - name: "collection3"
      version: "version: ''"

- name: set the namespace, name, and version keys to None
  lineinfile:
    path: "{{ galaxy_dir }}/dev/ansible_collections/dev/collection4/galaxy.yml"
    line: "{{ item.after }}"
    regexp: "{{ item.before }}"
  loop:
  - before: "^namespace: dev"
    after: "namespace:"
  - before: "^name: collection4"
    after: "name:"
  - before: "^version: 1.0.0"
    after: "version:"

- name: replace galaxy.yml content with a string
  copy:
    content: "invalid"
    dest: "{{ galaxy_dir }}/dev/ansible_collections/dev/collection5/galaxy.yml"

- name: remove galaxy.yml key required by build
  lineinfile:
    path: "{{ galaxy_dir }}/dev/ansible_collections/dev/collection6/galaxy.yml"
    line: "version: 1.0.0"
    state: absent

- name: list collections in development without semver versions
  command: ansible-galaxy collection list {{ galaxy_verbosity }}
  register: list_result
  environment:
    ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod"

- assert:
    that:
      - "'dev.collection1 *' in list_result.stdout"
      # Note the version displayed is the 'placeholder' string rather than "*" since it is not falsey
      - "'dev.collection2 placeholder' in list_result.stdout"
      - "'dev.collection3 *' in list_result.stdout"
      - "'dev.collection4 *' in list_result.stdout"
      - "'dev.collection5 *' in list_result.stdout"
      - "'dev.collection6 *' in list_result.stdout"

- name: list collections in human format
  command: ansible-galaxy collection list --format human
  register: list_result_human
  environment:
    ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod"

- assert:
    that:
      - "'dev.collection1 *' in list_result_human.stdout"
      # Note the version displayed is the 'placeholder' string rather than "*" since it is not falsey
      - "'dev.collection2 placeholder' in list_result_human.stdout"
      - "'dev.collection3 *' in list_result_human.stdout"
      - "'dev.collection5 *' in list_result.stdout"
      - "'dev.collection6 *' in list_result.stdout"

- name: list collections in yaml format
  command: ansible-galaxy collection list --format yaml
  register: list_result_yaml
  environment:
    ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod"

- assert:
    that:
      - "item.value | length == 6"
      - "item.value['dev.collection1'].version == '*'"
      - "item.value['dev.collection2'].version == 'placeholder'"
      - "item.value['dev.collection3'].version == '*'"
      - "item.value['dev.collection5'].version == '*'"
      - "item.value['dev.collection6'].version == '*'"
  with_dict: "{{ list_result_yaml.stdout | from_yaml }}"

- name: list collections in json format
  command: ansible-galaxy collection list --format json
  register: list_result_json
  environment:
    ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod"

- assert:
    that:
      - "item.value | length == 6"
      - "item.value['dev.collection1'].version == '*'"
      - "item.value['dev.collection2'].version == 'placeholder'"
      - "item.value['dev.collection3'].version == '*'"
      - "item.value['dev.collection5'].version == '*'"
      - "item.value['dev.collection6'].version == '*'"
  with_dict: "{{ list_result_json.stdout | from_json }}"

- name: list single collection in json format
  command: "ansible-galaxy collection list {{ item.key }} --format json"
  register: list_single_result_json
  environment:
    ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod"
  with_dict: "{{ { 'dev.collection1': '*', 'dev.collection2': 'placeholder', 'dev.collection3': '*' } }}"

- assert:
    that:
      - "(item.stdout | from_json)[galaxy_dir + '/dev/ansible_collections'][item.item.key].version == item.item.value"
  with_items: "{{ list_single_result_json.results }}"

- name: list single collection in yaml format
  command: "ansible-galaxy collection list {{ item.key }} --format yaml"
  register: list_single_result_yaml
  environment:
    ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod"
  with_dict: "{{ { 'dev.collection1': '*', 'dev.collection2': 'placeholder', 'dev.collection3': '*' } }}"

- assert:
    that:
      - "(item.stdout | from_yaml)[galaxy_dir + '/dev/ansible_collections'][item.item.key].version == item.item.value"
  with_items: "{{ list_single_result_json.results }}"

- name: test that no json is emitted when no collection paths are usable
  command: "ansible-galaxy collection list --format json"
  register: list_result_error
  ignore_errors: True
  environment:
    ANSIBLE_COLLECTIONS_PATH: ""

- assert:
    that:
      - "'{}' not in list_result_error.stdout"

- name: install an artifact to the second collections path
  command: ansible-galaxy collection install namespace1.name1 -s galaxy_ng {{ galaxy_verbosity }} -p "{{ galaxy_dir }}/prod"
  environment:
    ANSIBLE_CONFIG: '{{ galaxy_dir }}/ansible.cfg'

- name: replace the artifact version
  lineinfile:
    path: "{{ galaxy_dir }}/prod/ansible_collections/namespace1/name1/MANIFEST.json"
    line: '  "version": null,'
    regexp: '  "version": .*'

- name: test listing collections in all paths
  command: ansible-galaxy collection list {{ galaxy_verbosity }}
  register: list_result
  ignore_errors: True
  environment:
    ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod"

- assert:
    that:
      - list_result is failed
      - "'is expected to have a valid SemVer version value but got None' in list_result.stderr"