diff --git a/meta/main.yml b/meta/main.yml index 6e070131edbf44499344e1b6724056b739063dc5..6a7f008c430ac3651dbd58e58b0a9ac558b29b87 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -5,8 +5,8 @@ galaxy_info: namespace: chriscroome description: Ansible role for installing Docker CE on Debian and Ubuntu company: Webarchitects Co-operative - license: license (GPLv3) - min_ansible_version: 2.9 + license: GNU General Public License v3.0 (GPLv3) + min_ansible_version: 2.10 platforms: - name: debian versions: diff --git a/tasks/local_facts.yml b/tasks/local_facts.yml index 721d9305fd2c92bac9259ded9986dba432b49f09..6ea58edced98748cbe35075993a85d316ec5e226 100644 --- a/tasks/local_facts.yml +++ b/tasks/local_facts.yml @@ -13,34 +13,51 @@ path: /etc/ansible/facts.d recurse: true state: directory - mode: 0700 + mode: 0755 owner: root group: root - - name: Ansible dpkg architecture local fact script present + - name: Ansible local facts scripts present ansible.builtin.template: - src: dpkg_arch.fact.j2 - dest: /etc/ansible/facts.d/dpkg_arch.fact - mode: 0700 + src: "{{ script }}.j2" + dest: "/etc/ansible/facts.d/{{ script }}" + mode: 0755 owner: root group: root - register: apt_arch_facts + loop: + - dpkg.fact + - gpg.fact + - bash.fact + loop_control: + loop_var: script - name: Re-read Ansible local facts ansible.builtin.setup: filter: ansible_local - - name: Check that ansible_local.dpkg_arch is defined + - name: Check that ansible_local facts are defined ansible.builtin.assert: that: - - ansible_local.dpkg_arch is defined + - ansible_local.dpkg is defined + - ansible_local.gpg is defined + - ansible_local.bash is defined - - name: Print Ansible dpkg --architecture variables + - name: Print Ansible local dpkg facts ansible.builtin.debug: - var: ansible_local.dpkg_arch + var: ansible_local.dpkg + verbosity: 2 + + - name: Print Ansible local gpg facts + ansible.builtin.debug: + var: ansible_local.gpg + verbosity: 2 + + - name: Print Ansible local bash facts + ansible.builtin.debug: + var: ansible_local.bash verbosity: 2 tags: - - docker + - docker - docker_local_facts ... diff --git a/tasks/main.yml b/tasks/main.yml index fcea900da8614e616b04939a0b6e1ca35fe98e59..4c12a5606b4e874be6228ce332e840d4f3ac0563 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,7 +4,10 @@ - name: Include Docker local facts tasks ansible.builtin.include_tasks: local_facts.yml - when: ansible_local.dpkg_arch is not defined + when: > + ( ansible_local.dpkg.arch is not defined ) or + ( ansible_local.gpg.version is not defined ) or + ( ansible_local.bash.path is not defined ) tags: - docker_apt - docker_compose_v1 diff --git a/templates/bash.fact.j2 b/templates/bash.fact.j2 new file mode 100644 index 0000000000000000000000000000000000000000..27caa9325e2fc52f690622d587a5da6e9344b15c --- /dev/null +++ b/templates/bash.fact.j2 @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# {{ ansible_managed }} + +set -euo pipefail +BASH_PATH=$(which bash) + +if [[ -f "${BASH_PATH}" ]]; then + jo state=present path="${BASH_PATH}" +else + jo state=absent +fi diff --git a/templates/docker.sources.j2 b/templates/docker.sources.j2 index 126fcc2e183614df4b24fcf7e02eba1feddf81bb..48ef3de5c053ba9cefd16c894f0a2811aa3d3279 100644 --- a/templates/docker.sources.j2 +++ b/templates/docker.sources.j2 @@ -2,7 +2,7 @@ Types: deb URIs: https://download.docker.com/linux/{{ ansible_distribution | lower }} -Architectures: {{ ansible_facts.ansible_local.dpkg_arch.arch }} +Architectures: {{ ansible_facts.ansible_local.dpkg.arch }} Components: stable Suites: {{ ansible_distribution_release }} Signed-By: /etc/apt/keyrings/docker.gpg diff --git a/templates/dpkg.fact.j2 b/templates/dpkg.fact.j2 new file mode 100644 index 0000000000000000000000000000000000000000..e6aefb665ff8294d9420e2db4df7bc4536d9078f --- /dev/null +++ b/templates/dpkg.fact.j2 @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# {{ ansible_managed }} + +set -euo pipefail +DPKG="{{ apt_dpkg }}" + +if [[ -f "${DPKG}" ]]; then + ARCH=$("${DPKG}" --print-architecture) + jo state=present arch="${ARCH}" +else + jo state=absent +fi diff --git a/templates/gpg.fact.j2 b/templates/gpg.fact.j2 new file mode 100644 index 0000000000000000000000000000000000000000..a6e1fc666eb86a794b642da7c910314b23048b66 --- /dev/null +++ b/templates/gpg.fact.j2 @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# {{ ansible_managed }} + +set -euo pipefail +GPG="{{ apt_gpg }}" + +if [[ -f "${GPG}" ]]; then + VERSION=$("${GPG}" --version | head -n1 | awk '{ print $3 }') + jo state=present version="${VERSION}" +else + jo state=absent +fi