From 7f156f22c70e0a1b35095ac07949864eb6d94fb8 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Mon, 23 Dec 2019 15:39:26 -0600 Subject: [PATCH] Make pre-molecule tox playbook platform agnostic This change updates the tox molecule playbook to make it platform agnostic by moving the OS specific package lists into var files that will be dynamically loaded based on the operating system the playbook is being executed against. This is being done so that we can use molecule on OS's like CentOS, Ubuntu, SUSE, Debian, etc. While the only platforms supported at this time are Red Hat based, this change will allow additional var files to be added enabling additional platforms without needing any chanages to our task structure. > The linters job has been updated to exclude vars files from the ansible lint playbook commands. This is done because the playbook commands assume all found files are playbooks. Change-Id: I88f3551838e3676374d0a795631c8769ba40fbf4 Signed-off-by: Kevin Carter --- playbooks/tox/pre-molecule.yaml | 44 +++++++++++++++----------------- playbooks/tox/vars/redhat-7.yaml | 6 +++++ playbooks/tox/vars/redhat-8.yaml | 6 +++++ tox.ini | 4 +-- 4 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 playbooks/tox/vars/redhat-7.yaml create mode 100644 playbooks/tox/vars/redhat-8.yaml diff --git a/playbooks/tox/pre-molecule.yaml b/playbooks/tox/pre-molecule.yaml index 4c221ddbf..ecbe124b4 100644 --- a/playbooks/tox/pre-molecule.yaml +++ b/playbooks/tox/pre-molecule.yaml @@ -1,29 +1,27 @@ - hosts: all + vars: + tox_molecule_packages: "{{ _tox_molecule_packages | default([]) }}" tasks: + - name: Gather variables for each operating system + include_vars: "{{ item }}" + with_first_found: + - skip: true + files: + - "vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yaml" + - "vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yaml" + - "vars/{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yaml" + - "vars/{{ ansible_distribution | lower }}.yaml" + - "vars/{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yaml" + - "vars/{{ ansible_os_family | lower }}.yaml" + tags: + - always - # psutil->python-devel - # psutil->gcc - # ansible->selinux - - name: install packages needed by molecule - when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int >= 8 + - name: Install packages needed by molecule become: true package: - name: - - python2-devel - - python2-libselinux - - python3-devel - - python3-libselinux - - gcc + name: "{{ tox_molecule_packages }}" + when: + - (tox_molecule_packages | length) > 0 - - name: install packages needed by molecule - when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int < 8 - become: true - package: - name: - - python-devel - - libselinux-python - - gcc - - - name: install docker - include_role: - name: install-docker + roles: + - role: install-docker diff --git a/playbooks/tox/vars/redhat-7.yaml b/playbooks/tox/vars/redhat-7.yaml new file mode 100644 index 000000000..e4de3ed86 --- /dev/null +++ b/playbooks/tox/vars/redhat-7.yaml @@ -0,0 +1,6 @@ +--- + +_tox_molecule_packages: + - python-devel + - libselinux-python + - gcc diff --git a/playbooks/tox/vars/redhat-8.yaml b/playbooks/tox/vars/redhat-8.yaml new file mode 100644 index 000000000..37b996fa4 --- /dev/null +++ b/playbooks/tox/vars/redhat-8.yaml @@ -0,0 +1,6 @@ +--- + +_tox_molecule_packages: + - python3-devel + - python3-libselinux + - gcc diff --git a/tox.ini b/tox.ini index 2fde03a21..51461d489 100644 --- a/tox.ini +++ b/tox.ini @@ -43,12 +43,12 @@ commands = # Ansible lint # [ANSIBLE0012] Commands should not change things if nothing needs doing # [204] Lines should be no longer than 160 chars - bash -c "find playbooks -type f -regex '.*.ya?ml' -print0 | \ + bash -c "find playbooks -type f -regex '.*.ya?ml' ! -regex '.*vars\/.*' -print0 | \ xargs -t -n1 -0 ansible-lint -xANSIBLE0012,204" bash -c 'find roles -maxdepth 1 -mindepth 1 -type d -printf "%p/\n" | \ xargs -t -n1 ansible-lint -xANSIBLE0012,204' # Ansible Syntax Check - bash -c "find playbooks -type f -regex '.*.ya?ml' -exec \ + bash -c "find playbooks -type f -regex '.*.ya?ml' ! -regex '.*vars\/.*' -exec \ ansible-playbook --syntax-check -i {toxinidir}/tests/inventory \{\} + > /dev/null" {toxinidir}/tools/check_jobs_documented.py