- name: Setup vault SSH keys become: "{{ 'no' if inventory_hostname in ['sectorq.cloud', 'nas.home.lan'] else 'yes' }}" block: - name: Facts ansible.builtin.setup: when: ansible_facts.architecture is not defined - name: Install dependencies apt: name: - wget - unzip - gnupg - python3-debian state: present update_cache: yes - name: Download HashiCorp GPG key ansible.builtin.get_url: url: https://apt.releases.hashicorp.com/gpg dest: /tmp/hashicorp.gpg mode: '0644' - name: Dearmor HashiCorp GPG key ansible.builtin.command: cmd: gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg /tmp/hashicorp.gpg args: creates: /usr/share/keyrings/hashicorp-archive-keyring.gpg - name: Read os-release ansible.builtin.slurp: src: /etc/os-release register: os_release - name: Extract UBUNTU_CODENAME ansible.builtin.set_fact: ubuntu_codename: "{{ (os_release.content | b64decode).split('\n') | select('match', '^UBUNTU_CODENAME=') | map('regex_replace', '^UBUNTU_CODENAME=', '') | first }}" - name: Add HashiCorp APT repository ansible.builtin.apt_repository: repo: >- deb [arch={{ ansible_architecture }} signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com {{ ubuntu_codename }} main filename: hashicorp state: present - name: Update apt cache ansible.builtin.apt: update_cache: yes - name: Install Vault apt: name: vault state: present update_cache: yes - name: Set vault address copy: dest: /etc/profile.d/vault.sh content: "export VAULT_ADDR=http://vault.home.lan:8205\n" owner: root group: root mode: '0644' - name: Read SSH CA public key from Vault ansible.builtin.command: cmd: vault read -field=public_key ssh/config/ca register: vault_ca changed_when: false environment: VAULT_ADDR: "{{ vault_addr }}" VAULT_TOKEN: "{{ vault_token }}" - name: Install trusted SSH user CA ansible.builtin.copy: content: "{{ vault_ca.stdout }}\n" dest: /etc/ssh/trusted-user-ca-keys.pem owner: root group: root mode: '0644' - name: Enable Trusted User CA ansible.builtin.lineinfile: path: /etc/ssh/sshd_config regexp: "^TrustedUserCAKeys" line: "TrustedUserCAKeys /etc/ssh/trusted-user-ca-keys.pem" state: present - name: Enable PubkeyAuthentication ansible.builtin.lineinfile: path: /etc/ssh/sshd_config regexp: "^PubkeyAuthentication.*" line: "PubkeyAuthentication yes" state: present - name: Create vault agent dir file: path: /etc/vault-agent state: directory owner: root group: root mode: '0644' - name: Create vault agent config copy: dest: /etc/vault-agent/config.hcl content: | vault { address = "http://vault.home.lan:8205" } auto_auth { method "approle" { mount_path = "auth/approle" config = { role_id_file_path = "/etc/vault-agent/role_id" secret_id_file_path = "/etc/vault-agent/secret_id" remove_secret_id_file_after_reading = false } } sink "file" { config = { path = "/tmp/vault-token" } } } template { destination = "/home/jd/.ssh/id_ed25519-cert.pub" perms = "0644" user = "jd" group = "jd" contents = <