I have the below playbook. Created ssh keys for dave on the localhost (ansible master) and trying to create some users, groups and copy over ssh keys for some users all in the playbook.
All works well until the copying over ssh keys part. Ive confirmed the directory and public key exists for dave on the localhost…and the playbook created /home/dave/.ssh on the remote host
Not sure why this would fail?
Playbook output -
TASK [Copy ths ssh public key into the authorized key dir on the remote host] ********
failed: [10.10.0.5 → localhost] (item=frank) => {“failed”: true, “item”: “frank”, “ms g”: “Unable to find ‘/home/frank/.ssh/id_rsa.pub’ in expected paths.”}
failed: [10.10.0.5 → localhost] (item=joe) => {“failed”: true, “item”: “joe”, “msg”: “Unable to find ‘/home/joe/.ssh/id_rsa.pub’ in expected paths.”}
…ignoring
failed: [10.10.0.5 → localhost] (item=dave) => {“failed”: true, “item”: “dave”, “msg” : “Unable to find ‘/home/dave/.ssh/id_rsa.pub’ in expected paths.”}
Playbook -
[ansible@localhost playbooks]$ vi userscreate.yml
Permissions perhaps?
Keep in mind that you are able to use elevated privileges on the
target host, so you have no problem writing files to user's home
directories.
But it's likely that your own local account (the one you run your
playbook as) usually does *not* have permission to access other local
accounts (such as /home/dave) for obvious reasons.
Good point. The fact the playbook has become: yes in it - does that not apply to the commands that run on the localhost and the target? This playbook is just running against the target 10.10.0.5
Maybe I’m misunderstanding the use of the elevated permissions…
Thanks. So its clear why this didnt work. Can I ask you how I can tell the playbook to switch to root to execute the commands on the localhost with escalated privileges?
will work but then you're running the whole play as local root, which
feels wrong.
I can't think why you'd want to do that, if you aren't making changes
to that host.
In this example you're shipping public keys, there's no downside to having them
locally (or better still version controlled, so you remove a
particular workstation
as a single point of failure).