-
Notifications
You must be signed in to change notification settings - Fork 0
/
_run_component.yml
49 lines (43 loc) · 2.16 KB
/
_run_component.yml
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
---
- name: Install component Ansible Galaxy dependencies
tags: molecule-idempotence-notest
block:
- name: Check for plugin requirements file
stat:
path: /rsc/plugins/{{ remote_plugin.script_folder }}/requirements.yml
register: register_requirements_1
- name: Check for plugin requirements file 2
stat:
path: /rsc/plugins/{{ remote_plugin.script_folder }}/{{ remote_plugin.path | dirname }}/requirements.yml
register: register_requirements_2
- name: Set path to file 1 if it exists
set_fact:
requirements_path: "{{ register_requirements_1.stat.path }}"
when: register_requirements_1.stat.exists
- name: Set path to file 2 if file 1 does not exist and file 2 exists
set_fact:
requirements_path: "{{ register_requirements_2.stat.path }}"
when: not register_requirements_1.stat.exists and register_requirements_2.stat.exists
- name: Install role dependencies for Ansible plugin
when: requirements_path is defined
command: |
ansible-galaxy role install -r {{ requirements_path }} -p /rsc/plugins/{{ remote_plugin.script_folder | basename }}
args:
chdir: /rsc/plugins/{{ remote_plugin.script_folder | basename }}
executable: /bin/bash
- name: Install collection dependencies for Ansible plugin
when: requirements_path is defined
command: |
ansible-galaxy collection install -r {{ requirements_path }} -p /rsc/plugins/{{ remote_plugin.script_folder | basename }}/collections
args:
chdir: /rsc/plugins/{{ remote_plugin.script_folder | basename }}
executable: /bin/bash
- name: Test the component by executing it using ansible on the workspace
ansible.builtin.command: >
ansible-playbook -c local -v -b {{ remote_plugin.arguments }} -e='{{ remote_plugin.parameters }}' /rsc/plugins/{{ remote_plugin.script_folder
}}/{{remote_plugin.path }}
register: ansible_on_workspace
changed_when: >
ansible_on_workspace.stdout_lines is not defined or
'changed=0' not in
ansible_on_workspace.stdout_lines[ lookup('ansible.utils.index_of', ansible_on_workspace.stdout_lines, 'regex', '\s*PLAY RECAP\s*')+1 ]