Fix: Update docker install ansible role 34/72634/1
authorAnil Belur <abelur@linuxfoundation.org>
Sun, 11 Feb 2024 02:21:42 +0000 (12:21 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Sun, 11 Feb 2024 02:21:42 +0000 (12:21 +1000)
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 <abelur@linuxfoundation.org>
Change-Id: Ic12f9ef7549ed924117446a00f066e4bf110b694

.yamllint
meta/main.yml
molecule/default/molecule.yml
tasks/main.yml
tox.ini

index 7626c6e..894450c 100644 (file)
--- 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/
index 0ae59e0..02977b4 100644 (file)
@@ -21,6 +21,7 @@ galaxy_info:
       versions:
         - bionic
         - focal
+        - jammy
 
   galaxy_tags:
     - containers
index c71d938..75348fb 100644 (file)
@@ -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:
index 2e9698a..252ecd7 100644 (file)
@@ -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
         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
           - 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
         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
           - 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'
   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'
   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 (file)
--- 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