Skip to content

Commit

Permalink
Install dependencies before running component
Browse files Browse the repository at this point in the history
  • Loading branch information
dometto committed Nov 18, 2024
1 parent 5fffff1 commit 440755f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
46 changes: 46 additions & 0 deletions _run_component.yml
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 38 in _run_component.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: ansible-playbook -c local -v -b {{ remote_plugin.arguments }} --extra-vars='{{ remote_plugin.parameters }}' /rsc/plugins/ {{ remote_plugin.script_folder }}/{{remote_plugin.path }}
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 ]
12 changes: 4 additions & 8 deletions converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}"

0 comments on commit 440755f

Please sign in to comment.