Thanks for that. I eventually managed to get it working via this method:
---
- hosts: all
tasks:
- set_fact:
username: "{{ username | default(ansible_user_id) }}"
- set_fact:
keyfile: "{{ keyfile | default('/home/' + username +
'/.ssh/id_rsa.pub') }}"
- set_fact:
ssh_public_key: "{{ lookup('file', '{{ keyfile }}') }}"
Interestingly, or not, it fails if I attempt to collapse the three set_fact
statements into one stanza:
TASK [set_fact]
***************************************************************************************************************************************************************************************************
fatal: [dgsdtstlum01.local]: FAILED! => {"failed": true, "msg": "the field
'args' has an invalid value, which appears to include a variable that is
undefined. The error was: 'username' is undefined\n\nThe error appears to
have been in '/home/mbrooks/ansible-config/books/distribute_ssh_key.yaml':
line 5, column 7, but may\nbe elsewhere in the file depending on the exact
syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n -
set_fact:\n ^ here\n"}
Some kind of scope guarding? Moustaches not stacking noted, thankyou.
Mart.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5d757bca-03d0-445d-893a-41d0b39ba724%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.