diff --git a/_run_component.yml b/_run_component.yml new file mode 100644 index 0000000..9a3ceef --- /dev/null +++ b/_run_component.yml @@ -0,0 +1,46 @@ +--- +- name: Check for plugin requirements file + stat: + path: /rsc/plugins/{{ remote_plugin.script_folder | basename }}/requirements.yml + register: register_requirements_1 + +- name: Check for plugin requirements file 2 + stat: + path: /rsc/plugins/{{ remote_plugin.script_folder | basename }}/{{ remote_plugin.path | dirname }}/requirements.yml + register: register_requirements_2 + +- name: Set path to file 1 if it exists + set_fact: + requirements_path: /rsc/plugins/{{ remote_plugin.script_folder | basename }}/requirements.yml + 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: /rsc/plugins/{{ remote_plugin.script_folder | basename }}/{{ remote_plugin.path | dirname }}/requirements.yml + when: not register_requirements_1.stat.exists and register_requirements_2.stat.exists + +- name: Install role dependencies for Ansible plugin + 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 + when: requirements_path is defined + +- name: Install collection dependencies for Ansible plugin + 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 + when: requirements_path is defined + +- name: Test the component by executing it using ansible on the workspace + ansible.builtin.command: > + ansible-playbook -c local -v -b {{ remote_plugin.arguments }} --extra-vars='{{ 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 ] diff --git a/converge.yml b/converge.yml index 13d916b..a45d60b 100644 --- a/converge.yml +++ b/converge.yml @@ -8,17 +8,13 @@ msg: "{{ item.name }}" with_items: "{{ lookup('env', 'components') }}" - - name: Test the component by executing it using ansible on the workspace - ansible.builtin.command: > - ansible-playbook -c local -v -b {{ remote_plugin.arguments }} --extra-vars='{{ remote_plugin.parameters }}' /rsc/plugins/{{ item.name}}/{{ item.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 ] + - name: Run components + ansible.builtin.include_tasks: _run_component.yml vars: remote_plugin: script_type: Ansible PlayBook arguments: -i 127.0.0.1, --skip-tags {{ ansible_skip_tags | join(',') }} parameters: "{{ item.parameters | default({}) | to_json }}" + script_folder: "{{ item.name }}" + path: "{{ item.path }}" with_items: "{{ lookup('env', 'components') }}"