Skip to content

Commit

Permalink
Allow specifying python and ansible versions per component
Browse files Browse the repository at this point in the history
  • Loading branch information
dometto committed Aug 5, 2024
1 parent 1612bfe commit e9b6f72
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 15 deletions.
26 changes: 26 additions & 0 deletions _run_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: "Set python version for component {{ item.name }}"
ansible.builtin.set_fact:
python_version: "{{ item.python_version | default('3.10') }}"

- name: "Set remote ansible version for component {{ item.name }}"
ansible.builtin.set_fact:
remote_ansible_version: "{{ item.remote_ansible_version | default('9.1.0') }}"

- name: Setup ansible
ansible.builtin.include_tasks: _setup_ansible.yml

- 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='ansible_python_interpreter={{ ansible_interpreter }}'
--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[-1]"
vars:
ansible_interpreter: "{{ python_location }}"
remote_plugin:
script_type: Ansible PlayBook
arguments: -i 127.0.0.1, --skip-tags {{ ansible_skip_tags | join(',') }}
parameters: "{{ item.parameters | default({}) | to_json }}"
37 changes: 37 additions & 0 deletions _setup_ansible.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- name: Install Python and Ansible for Ubuntu
when: ansible_distribution == 'Ubuntu'
block:

- name: Set deadsnakes key download location
ansible.builtin.set_fact:
key_location: /usr/share/keyrings/deadsnakes.asc

- name: Download deadsnakes key
ansible.builtin.get_url:
url: https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xf23c5a6cf475977595c89f51ba6932366a755776
dest: "{{ key_location }}"
when: ansible_pkg_mgr == 'apt'

- name: Add deadsnakes repo
apt_repository:
repo: "deb [signed-by={{ key_location }}] https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu {{ ansible_distribution_release }} main"
state: present
filename: deadsnakes

- name: Install python
apt:
pkg:
- "python{{ python_version }}"
- "python{{ python_version }}-venv"
state: present

- name: Install ansible
pip:
name: "ansible=={{ remote_ansible_version }}"
virtualenv: "/root/ansible_env{{ python_version }}"
virtualenv_command: "python{{ python_version }} -m venv"

- name: Set python location
ansible.builtin.set_fact:
python_location: "/root/ansible_env{{ python_version }}/bin/python3"

Check failure on line 37 in _setup_ansible.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[new-line-at-end-of-file]

No new line character at the end of file

Check failure on line 37 in _setup_ansible.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[new-line-at-end-of-file]

No new line character at the end of file

Check failure on line 37 in _setup_ansible.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[new-line-at-end-of-file]

No new line character at the end of file

Check failure on line 37 in _setup_ansible.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[new-line-at-end-of-file]

No new line character at the end of file
14 changes: 3 additions & 11 deletions converge.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
---
- name: Converge
hosts: all
gather_facts: false
gather_facts: true
tasks:
- name: Debug -- list all components to be executed
ansible.builtin.debug:
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[-1]"
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 }}"
- name: Run component
ansible.builtin.include_tasks: _run_component.yml
with_items: "{{ lookup('env', 'components') }}"
8 changes: 4 additions & 4 deletions prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
ssh_connection_multiplexing: true
with_items: "{{ lookup('env', 'components') }}"

# Apt cache is normally updated at deploy time by the SRC-OS component.
# Make sure it is fresh so our tests use recent apt repo information.
- name: Update apt cache
- name: Install dependencies
ansible.builtin.apt:
pkg:
- dirmngr
update_cache: true
when: ansible_os_family == 'Debian'
when: ansible_pkg_mgr == 'apt'

- name: Set extra_preparations var
ansible.builtin.set_fact:
Expand Down

0 comments on commit e9b6f72

Please sign in to comment.