ansible/roles/docker/tasks/setup_gpg_key.yml
ilia 83a5d988af
Some checks failed
CI / lint-and-test (pull_request) Successful in 58s
CI / ansible-validation (pull_request) Successful in 2m17s
CI / secret-scanning (pull_request) Successful in 53s
CI / dependency-scan (pull_request) Successful in 57s
CI / sast-scan (pull_request) Successful in 2m17s
CI / license-check (pull_request) Successful in 55s
CI / vault-check (pull_request) Successful in 2m20s
CI / playbook-test (pull_request) Successful in 2m16s
CI / container-scan (pull_request) Successful in 1m25s
CI / sonar-analysis (pull_request) Failing after 1m56s
CI / workflow-summary (pull_request) Successful in 50s
Fix: Update ansible-lint configuration to exclude specific paths and skip certain rules for improved linting flexibility
2025-12-14 21:04:45 -05:00

46 lines
1.4 KiB
YAML

---
- name: Check if Docker GPG key exists and is correct
ansible.builtin.shell: |
if [ -f /etc/apt/keyrings/docker.gpg ]; then
if file /etc/apt/keyrings/docker.gpg | grep -q "PGP"; then
echo "correct_key"
else
echo "wrong_key"
fi
else
echo "not_exists"
fi
register: docker_key_check
failed_when: false
changed_when: false
- name: Remove incorrect Docker GPG key
ansible.builtin.file:
path: /etc/apt/keyrings/docker.gpg
state: absent
become: true
when: docker_key_check.stdout == "wrong_key"
- name: Download Docker's official GPG key only if needed
ansible.builtin.get_url:
url: https://download.docker.com/linux/ubuntu/gpg
dest: /tmp/docker.gpg
mode: '0644'
when: docker_key_check.stdout in ["not_exists", "wrong_key"]
- name: Convert and install Docker GPG key only if needed
ansible.builtin.shell: gpg --dearmor < /tmp/docker.gpg > /etc/apt/keyrings/docker.gpg
changed_when: false
when: docker_key_check.stdout in ["not_exists", "wrong_key"]
- name: Set permissions on Docker GPG key only if needed
ansible.builtin.file:
path: /etc/apt/keyrings/docker.gpg
mode: '0644'
when: docker_key_check.stdout in ["not_exists", "wrong_key"]
- name: Clean up temporary GPG key file
ansible.builtin.file:
path: /tmp/docker.gpg
state: absent
when: docker_key_check.stdout in ["not_exists", "wrong_key"]