main.yml (1428B)
1 --- 2 - name: Verify gpg-agent is running 3 ansible.builtin.command: 4 cmd: gpg-agent --version 5 changed_when: false 6 register: ssh_gpg_agent_check 7 failed_when: ssh_gpg_agent_check.rc != 0 8 9 - name: Ensure .ssh directory exists 10 ansible.builtin.file: 11 path: "{{ ansible_facts['user_dir'] }}/.ssh" 12 state: directory 13 mode: "0700" 14 15 - name: Write ansible SSH private key 16 ansible.builtin.copy: 17 content: "{{ lookup('pipe', 'pass show ssh/id_ed25519_ansible') }}\n" 18 dest: "{{ ansible_facts['user_dir'] }}/.ssh/id_ed25519_ansible" 19 mode: "0600" 20 no_log: true 21 22 - name: Derive and write ansible SSH public key 23 ansible.builtin.shell: 24 cmd: ssh-keygen -y -f {{ ansible_facts['user_dir'] }}/.ssh/id_ed25519_ansible > {{ ansible_facts['user_dir'] }}/.ssh/id_ed25519_ansible.pub 25 changed_when: false 26 27 - name: Deploy SSH config 28 ansible.builtin.template: 29 src: config.j2 30 dest: "{{ ansible_facts['user_dir'] }}/.ssh/config" 31 mode: "0600" 32 33 - name: Fetch Gitea host key 34 ansible.builtin.command: 35 cmd: ssh-keyscan -4 -p 2222 gitea.learningunix.net 36 register: ssh_gitea_host_key 37 changed_when: false 38 39 - name: Add Gitea host key to known_hosts 40 ansible.builtin.known_hosts: 41 name: "[gitea.learningunix.net]:2222" 42 key: "{{ item }}" 43 path: "{{ ansible_facts['user_dir'] }}/.ssh/known_hosts" 44 state: present 45 loop: "{{ ssh_gitea_host_key.stdout_lines | reject('match', '^#') | list }}"