feat(common): Arreglo de known_hosts

This commit is contained in:
Rénich Bon Ćirić 2025-11-15 19:59:05 -06:00
commit 08c38d3d56
Signed by: renich
GPG key ID: AB2A9F49384FE324

View file

@ -18,6 +18,7 @@
- name: "Generate: Koji Certificate Authority (CA)"
tags: ca
when: inventory_hostname == 'localhost'
block:
- name: "Generate CA private key"
community.crypto.openssl_privatekey:
@ -50,12 +51,14 @@
- name: "Generate: Component and User Certificates"
ansible.builtin.include_tasks: generate_single_cert.yaml
loop: "{{ koji_certs_to_generate }}"
loop: "{{ common_koji_certs_to_generate }}"
loop_control:
loop_var: cert
when: inventory_hostname == 'localhost'
tags: components
- name: Create GPG key batch file
when: inventory_hostname == 'localhost'
ansible.builtin.copy:
content: |
%echo Generating a basic OpenPGP key
@ -75,16 +78,17 @@
run_once: true
- name: Generate GPG key
ansible.builtin.shell:
ansible.builtin.command:
cmd: "gpg --batch --gen-key {{ koji_pki_dir }}/gpg_batch"
creates: "{{ koji_pki_dir }}/gpg_key.pub"
delegate_to: localhost
run_once: true
args:
creates: "{{ koji_pki_dir }}/gpg_key.pub"
- name: Export GPG public key
ansible.builtin.shell:
cmd: "gpg --armor --export 'Koji Signing Key' > {{ koji_pki_dir }}/gpg_key.pub"
creates: "{{ koji_pki_dir }}/gpg_key.pub"
changed_when: false
delegate_to: localhost
run_once: true
@ -102,17 +106,23 @@
- name: Flush systemd journal to disk
ansible.builtin.command: journalctl --flush
changed_when: false
when: inventory_hostname != 'localhost'
- name: "Remove existing host keys"
ansible.builtin.shell:
cmd: "ssh-keygen -R {{ item }}"
loop: "{{ groups['all'] }}"
ignore_errors: true
- name: "Add new host keys"
- name: "Manage known_hosts"
tags: ssh
block:
- name: "Remove existing host keys"
ansible.builtin.known_hosts:
path: "~/.ssh/known_hosts"
name: "{{ item }}"
key: "{{ lookup('pipe', 'ssh-keyscan -t rsa {{ item }}') }}"
state: absent
loop: "{{ groups['all'] }}"
- name: "Add current host keys"
ansible.builtin.known_hosts:
path: "~/.ssh/known_hosts"
name: "{{ item }}"
key: "{{ lookup('pipe', 'ssh-keyscan -t rsa ' + item) }}"
state: present
loop: "{{ groups['all'] }}"