From caf6f814927bc54a0b169c468bba832217fc63ab Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Sun, 11 Feb 2024 12:21:42 +1000 Subject: [PATCH] Fix: Update docker install ansible role 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. Signed-off-by: Anil Belur Change-Id: Ic12f9ef7549ed924117446a00f066e4bf110b694 --- .yamllint | 4 +--- meta/main.yml | 1 + molecule/default/molecule.yml | 10 ++++---- tasks/main.yml | 54 +++++++++++++++++++++---------------------- tox.ini | 34 +++++++++++++++++---------- 5 files changed, 57 insertions(+), 46 deletions(-) diff --git a/.yamllint b/.yamllint index 7626c6e..894450c 100644 --- a/.yamllint +++ b/.yamllint @@ -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/ diff --git a/meta/main.yml b/meta/main.yml index 0ae59e0..02977b4 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -21,6 +21,7 @@ galaxy_info: versions: - bionic - focal + - jammy galaxy_tags: - containers diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index c71d938..75348fb 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -3,10 +3,6 @@ dependency: name: galaxy driver: name: docker -lint: | - set -e - yamllint . - ansible-lint tasks/*.yml platforms: - name: centos7 image: centos:7 @@ -40,6 +36,12 @@ platforms: image: ubuntu:20.04 groups: - ubuntu_version + - name: ubuntu2204 + image: ubuntu:22.04 + - name: ubuntu2204-version + image: ubuntu:22.04 + groups: + - ubuntu_version provisioner: name: ansible inventory: diff --git a/tasks/main.yml b/tasks/main.yml index 2e9698a..252ecd7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,53 +1,55 @@ --- - name: "Checking for x86_64" - set_fact: + ansible.builtin.set_fact: host_arch: "amd64" when: "'x86_64' in ansible_architecture" - name: "Checking for aarch64" - set_fact: + ansible.builtin.set_fact: host_arch: "arm64" when: "'aarch64' in ansible_architecture" - name: "Checking for Centos docker version" - set_fact: + ansible.builtin.set_fact: docker_ce_name: 'docker-ce-{{ centos_docker_version }}' when: - ansible_os_family == 'RedHat' - centos_docker_version != 'latest' - name: "Checking for Ubuntu docker version" - set_fact: + ansible.builtin.set_fact: docker_ce_name: 'docker-ce={{ ubuntu_docker_version }}' when: - ansible_distribution == 'Ubuntu' - ubuntu_docker_version != 'latest' - name: Install Docker (RedHat 7) + become: true + when: ansible_os_family == 'RedHat' and ansible_distribution_major_version == "7" block: - name: Install Docker requirements - yum: + ansible.builtin.yum: name: - device-mapper-persistent-data - lvm2 state: present - name: Add Docker repository - get_url: + ansible.builtin.get_url: url: https://download.docker.com/linux/centos/docker-ce.repo dest: /etc/yum.repos.d/docker-ce.repo mode: 0644 - name: Install Docker CE - yum: + ansible.builtin.yum: name: '{{ docker_ce_name }}' state: present update_cache: true - when: ansible_os_family == 'RedHat' and ansible_distribution_major_version == "7" - become: true - name: Install Docker (RedHat 8) + become: true + when: ansible_os_family == 'RedHat' and ansible_distribution_major_version >= "8" block: - name: Remove confliting packages with Docker-ce - yum: + ansible.builtin.yum: name: - atomic-registries - buildah @@ -60,12 +62,12 @@ state: absent update_cache: true - name: Add Docker repository - get_url: + ansible.builtin.get_url: url: https://download.docker.com/linux/centos/docker-ce.repo dest: /etc/yum.repos.d/docker-ce.repo mode: 0644 - name: Install Docker requirements - yum: + ansible.builtin.yum: name: - docker-ce - docker-ce-cli @@ -75,13 +77,13 @@ - docker-compose-plugin state: present update_cache: true - when: ansible_os_family == 'RedHat' and ansible_distribution_major_version >= "8" - become: true - name: Install Docker (Ubuntu) + become: true + when: ansible_distribution == 'Ubuntu' block: - name: Install Docker requirements - apt: + ansible.builtin.package: name: - apt-transport-https - ca-certificates @@ -89,15 +91,15 @@ state: present update_cache: true - name: Add Docker apt-key - apt_key: + ansible.builtin.apt_key: url: https://download.docker.com/linux/ubuntu/gpg state: present - name: Add Docker apt-repository - apt_repository: + ansible.builtin.apt_repository: repo: 'deb [arch={{ host_arch }}] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} {{ docker_repo_channel }}' state: present - name: Install Docker CE - apt: + ansible.builtin.package: name: - docker-ce - docker-ce-cli @@ -107,35 +109,33 @@ - docker-compose-plugin state: present update_cache: true - when: ansible_distribution == 'Ubuntu' - become: true - name: Copy LF Docker configuration + become: true block: - name: Ensure /etc/docker directory exists - file: + ansible.builtin.file: path: /etc/docker state: directory mode: 0700 - name: Copy LF Docker configuration - copy: + ansible.builtin.copy: src: daemon.json dest: /etc/docker/daemon.json owner: root group: root mode: 0600 - name: 'Set mtu to {{ mtu }}' - lineinfile: + ansible.builtin.lineinfile: path: /etc/docker/daemon.json regexp: '^ "mtu":' line: ' "mtu": {{ mtu }},' - become: true # There is a known bug with using a daemon.json file and passing the default # cli options to the daemon. We must replace the ExecStart command with one # that does not have any options. - name: Fix broken systemd file on Ubuntu - lineinfile: + ansible.builtin.lineinfile: path: /lib/systemd/system/docker.service regexp: '^ExecStart=' line: 'ExecStart=/usr/bin/dockerd' @@ -143,7 +143,7 @@ become: true - name: Fix broken systemd file on Red Hat - lineinfile: + ansible.builtin.lineinfile: path: /usr/lib/systemd/system/docker.service regexp: '^ExecStart=' line: 'ExecStart=/usr/bin/dockerd' @@ -151,7 +151,7 @@ become: true - name: Enable Docker service - systemd: + ansible.builtin.systemd: # noqa ignore-errors name: docker enabled: true ignore_errors: true diff --git a/tox.ini b/tox.ini index df67f4f..5ad109a 100644 --- a/tox.ini +++ b/tox.ini @@ -2,30 +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 = * -allowlist_externals = - ./molecule.sh commands = ./molecule.sh +allowlist_externals = + ./molecule.sh [testenv:pre-commit] -basepython = python3 +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 \ @@ -45,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 -- 2.16.6