I have an issue with looping on vars,
- hosts: all
become: yes
vars:
user:
- name: "neito"
pubkey: "{{ lookup('file', '~/.ssh/vsphere_vm.pub') }}"
privkey: "{{ lookup('file', '~/.ssh/vsphere_vm') }}"
tasks:
- name: "Add SSH public key"
authorized_key:
user: "{{ item.name }}"
key: "{{ item.pubkey }}"
loop:
- "{{ user }}"
when running this playbook I have the following error :
The error was: 'list object' has no attribute 'name'
The {{ item.name }} seems to be undefined for Ansible, I guess I'm missing something obvious here but I can't find what. (I was following this get started post
Edit 1 :
By declaring the vars like following it works :
vars:
user:
{
name: "neito",
pubkey: "{{ lookup('file', '~/.ssh/vsphere_vm.pub') }}",
privkey: "{{ lookup('file', '~/.ssh/vsphere_vm') }}",
}
Could someone still point me out why the first syntax didn't work?