Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install dependencies before running component #27

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions _run_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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

Check warning on line 41 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 }} -e='{{ remote_plugin.parameters }}' /rsc/plugins/{{ remote_plugin.script_folder }}/{{remote_plugin.path }}
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 ]
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') }}"
Loading