Open skibbipl opened 2 years ago
Ok, when I replaced:
key: "{{ lookup('fileglob', lookup('env','HOME') + '/.ssh/*.pub') }}"
with
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_ed25519.pub') }}"
it works. But I need wildcard selection :(
Likely too late for you @skibbipl but I ran into the same issue and worked around it via with_file and a fileglob lookup
e.g.
with_file: "{{ lookup('ansible.builtin.fileglob', 'files/ssh/*.pub').split(',') }}"
I ran into the same issue and worked around it via with_file and a fileglob lookup e.g.
with_file: "{{ lookup('ansible.builtin.fileglob', 'files/ssh/*.pub').split(',') }}"
This didn't work for for me and gave me the following error: AttributeError: 'list' object has no attribute 'startswith'
But this worked for me:
- name: Set up multiple authorized keys for user bird
ansible.posix.authorized_key:
user: "{{ hostvars[inventory_hostname].ansible_user }}"
state: present
key: "{{ lookup('ansible.builtin.file', item) }}"
with_fileglob:
- "public_keys/*"
@weichweich thanks for that, I see where I went wrong initally now.
I had something like this, using "item" directly for the key, which didn't work. Your lookup in "key" is the ... "key"
#wrong, don't use
- name: Set up multiple authorized keys
ansible.posix.authorized_key:
user: "foobar"
state: present
key: "{{ item }}"
with_fileglob:
- "public_keys/*"
SUMMARY
I'm trying to add my user ssh key to target machine. But I get invalid key specified
ISSUE TYPE
COMPONENT NAME
authorized_key
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Raspbian OS, bookworm (testing)
STEPS TO REPRODUCE
EXPECTED RESULTS
Key added to target machine
ACTUAL RESULTS