Skip to content

Commit

Permalink
Fix: Update lf-recommended-tools ansible role
Browse files Browse the repository at this point in the history
Update molecule test formats and update the role to build with
latest version of ansible. Fix ansible lint errors and warnings.

Update tox and pre-commit dependencies to build with latest versions
of ansible and molecule.

Fix up the ansible lint errors and warnings.

Rule Violation Summary:
count tag                   profile rule associated tags
1 command-instead-of-module basic   command-shell, idiom
1 no-free-form              basic   syntax, risk
1 name[missing]             basic   idiom
1 yaml[truthy]              basic   formatting, yaml

Change-Id: I35b22a5911cee7070571e7e3650ababd8de22738
Signed-off-by: Anil Belur <[email protected]>
  • Loading branch information
askb committed Feb 11, 2024
1 parent 774ccb3 commit 453eae3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 45 deletions.
4 changes: 1 addition & 3 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ rules:
max-spaces-inside: 1
level: error
line-length: disable
# NOTE(retr0h): Templates no longer fail this lint rule.
# Uncomment if running old Molecule templates.
# truthy: disable
truthy: disable

ignore: |
.tox/
4 changes: 0 additions & 4 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ dependency:
name: galaxy
driver:
name: docker
lint: |
set -e
yamllint .
ansible-lint tasks/*.yml
platforms:
- name: centos7
image: centos:7
Expand Down
15 changes: 8 additions & 7 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,34 @@

tasks:
- name: Update APT cache
apt:
ansible.builtin.package:
update_cache: yes
when: ansible_distribution == 'Ubuntu'
become: true

- rpm_key:
- name: Install GPG certs
ansible.builtin.rpm_key:
state: present
key: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-8
when: ansible_os_family == 'RedHat'
become: true

- name: Install EPEL repository
yum:
ansible.builtin.yum:
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm
state: present
when: ansible_os_family == 'RedHat'
become: true

- name: Install yum-plugin-versionlock
yum:
ansible.builtin.yum:
name:
- yum-plugin-versionlock
when: ansible_os_family == 'RedHat'
become: true

- name: Install mock
yum:
ansible.builtin.yum:
name:
- mock-2.17-1.el7
state: present
Expand All @@ -40,13 +41,13 @@
become: true

- name: Lock mock-core-configs version$
command: yum versionlock mock
ansible.builtin.command: yum versionlock mock
when:
- ansible_os_family == 'RedHat' and ansible_distribution_major_version == "7"
become: true

- name: Install mock-core-configs from remote repo
yum:
ansible.builtin.yum:
name: https://rpmfind.net/linux/epel/testing/7/aarch64/Packages/m/mock-core-configs-31.6-1.el7.noarch.rpm
state: present
when:
Expand Down
48 changes: 26 additions & 22 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,89 @@
---
- name: Load operating-system specific variables
include_vars: "{{ item }}"
ansible.builtin.include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml"
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"

# Required for direct install of parallel package from linuxsoft.cern.ch
- rpm_key:
- name: Install RPM GPG certs
ansible.builtin.rpm_key:
state: present
key: https://linuxsoft.cern.ch/cern/centos/7/os/x86_64/RPM-GPG-KEY-cern
when: ansible_os_family == 'RedHat'
become: true

- name: Install LF Recommended Tools on RedHat
yum:
ansible.builtin.yum:
name: "{{ lf_recommended_tools_packages }}"
state: present
when: ansible_os_family == 'RedHat'
become: true

- name: Install LF Recommended Tools on Debian
# Note: apt module requires state: 'fixed' not in dnf or yum modules
apt:
ansible.builtin.package:
name: "{{ lf_recommended_tools_packages }}"
state: fixed
when: ansible_os_family == 'Debian'
become: true

- name: Install fedora-packager
yum: name=fedora-packager state=present
ansible.builtin.yum:
name:
- fedora-packager
state: present
when: ansible_os_family == 'RedHat'
become: true

- name: Install PlantUML
become: true
block:
- name: Create /opt/plantuml install directory
file:
ansible.builtin.file:
path: /opt/plantuml
state: directory
mode: 0755
- name: Fetch PlantUML
get_url:
ansible.builtin.get_url:
url: https://sourceforge.net/projects/plantuml/files/plantuml.jar/download
validate_certs: no
validate_certs: false
dest: /opt/plantuml/plantuml.jar
mode: 0644
register: result
until: result is succeeded
retries: 3
delay: 30
- name: Install PlantUML executable script
copy:
ansible.builtin.copy:
content: |
#!/bin/sh
exec java -jar /opt/plantuml/plantuml.jar "$@"
dest: /usr/local/bin/plantuml
mode: 0755
become: true

- name: Add NodeSource repository/NodeJS
vars:
# Sets the packaged/baseline version of NodeJS
nodejs_version: "16.x"
block:
- name: Add NodeSource repository/NodeJS under RedHat/CentOS
become: true
when: ansible_facts['os_family'] == 'RedHat'
block:
- name: Set up the Nodesource RPM directory.
set_fact:
ansible.builtin.set_fact:
nodejs_rhel_rpm_dir: "pub_{{ nodejs_version }}"

- name: Import Nodesource RPM key
rpm_key:
ansible.builtin.rpm_key:
key:
https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL
state: present

- name: Add Nodesource repositories for Node.js (CentOS 7+).
yum:
ansible.builtin.yum:
name:
"https://rpm.nodesource.com/{{ nodejs_rhel_rpm_dir }}/el/\
{{ ansible_distribution_major_version }}/\
Expand All @@ -89,49 +94,48 @@
register: node_repo

- name: Update package cache if repo was added.
yum: update_cache=yes
ansible.builtin.yum: update_cache=yes
when: node_repo is changed
tags: ["skip_ansible_lint"]

- name: Ensure Node.js AppStream module is disabled (CentOS 8+).
ansible.builtin.command: yum module disable -y nodejs
ansible.builtin.command: yum module disable -y nodejs # noqa command-instead-of-module
register: module_disable
changed_when: "'Nothing to do.' not in module_disable.stdout"
when: ansible_distribution_major_version | int >= 8

- name: Ensure Node.js and npm are installed.
yum:
ansible.builtin.yum:
name: "nodejs-{{ nodejs_version | regex_replace('x', '') }}*"
state: present
become: true

- name: Add NodeSource repository/NodeJS under Ubuntu
become: true
when: ansible_facts['distribution'] == 'Ubuntu'
block:
- name: Import the NodeSource GPG key into apt
apt_key:
ansible.builtin.apt_key:
url: "https://keyserver.ubuntu.com/pks/lookup?\
op=get&fingerprint=on&search=0x1655A0AB68576280"
id: "68576280"
state: present

- name: Add NodeSource deb repository
apt_repository:
ansible.builtin.apt_repository:
repo: "deb https://deb.nodesource.com/node_{{ nodejs_version }} \
{{ ansible_distribution_release }} main"
state: present

- name: Add NodeSource deb-src repository
apt_repository:
ansible.builtin.apt_repository:
repo: "deb-src \
https://deb.nodesource.com/node_{{ nodejs_version }} \
{{ ansible_distribution_release }} main"
state: present

- name: Install Node.js
apt:
ansible.builtin.package:
pkg:
- nodejs
state: present
update_cache: true
become: true
29 changes: 20 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@
minversion = 1.6
envlist =
molecule,
pre-commit
pre-commit,
lint
skipsdist=true

[testenv:molecule]
basepython = python3
deps =
ansible~=2.9.6
ansible-lint~=4.2.0
detox~=0.18
ansible
docker
yamllint
molecule~=3.0.8
molecule[docker]
pytest~=5.4.0
molecule
molecule-docker
passenv = *
commands =
./molecule.sh
allowlist_externals =
./molecule.sh

[testenv:pre-commit]
allowlist_externals =
/bin/sh
deps = pre-commit
allowlist_externals = /bin/sh
passenv = HOME
commands =
pre-commit run --all-files --show-diff-on-failure
/bin/sh -c 'if ! git config --get user.name > /dev/null; then \
Expand All @@ -44,3 +43,15 @@ commands =
/bin/sh -c "if [ -f .git/REMOVE_USEREMAIL ]; then \
git config --global --unset user.email; \
rm -f .git/REMOVE_USEREMAIL; fi"

[testenv:lint]
basepython = python310
deps =
ansible-lint
yamllint
commands =
/bin/bash -c "ansible-lint tasks/*.yml"
yamllint .
allowlist_externals =
/bin/bash
yamllint

0 comments on commit 453eae3

Please sign in to comment.