--- - name: Generate local SSH config from Ansible inventory hosts: localhost gather_facts: false vars: ssh_config_file: "{{ lookup('env', 'HOME') }}/.ssh/config" ssh_identity_file: "~/.ssh/id_ed25519" ssh_host_suffix: "VM" ssh_config_marker: "# {mark} ANSIBLE MANAGED HOME VM HOSTS" tasks: - name: Ensure ~/.ssh directory exists ansible.builtin.file: path: "{{ lookup('env', 'HOME') }}/.ssh" state: directory mode: "0700" - name: Add Proxmox VM hosts to local SSH config ansible.builtin.blockinfile: path: "{{ ssh_config_file }}" create: true mode: "0600" marker: "{{ ssh_config_marker }}" block: | {% for host in groups["proxmox_vms"] %} Host {{ host }}{{ ssh_host_suffix }} HostName {{ hostvars[host]["ansible_host"] }} User {{ hostvars[host]["ansible_user"] | default("vrubel") }} IdentityFile {{ ssh_identity_file }} {% endfor %}