I'm having trouble with first-available file, which I'm using to
authorise a ssh key for a given user like so:
# TODO: add a forced-command so only gitpulling is allowed
- name: put coreapi public key in cms user XXXX for synching
authorized_key: user=XXXX state=present
key=$FILE({{item}})
first_available_file:
- keys/whitelabel_sites/{{deploy}}.coreapi.{{customer}}.enso_id_rsa.pub
- keys/javier
This is my debug playbook:
- name: find out why the key isn't getting proper authorised 0 --
the variable interpolation
debug: msg="keys/whitelabel_sites/{{deploy}}.coreapi.{{customer}}.enso_id_rsa.pub"
- name: find out why the key isn't getting proper authorised 1 -- the filename
debug: msg=$item
first_available_file:
- keys/whitelabel_sites/{{deploy}}.coreapi.{{customer}}.enso_id_rsa.pub
- keys/javier
- name: find out why the key isn't getting proper authorised 2 --
the file contents
debug: msg=$FILE({{item}})
first_available_file:
- keys/whitelabel_sites/{{deploy}}.coreapi.{{customer}}.enso_id_rsa.pub
- keys/javier
And this is the output: only the customer name has been changed to
"customername":
TASK: [find out why the key isn't getting proper authorised 0 -- the
variable interpolation] ****
ok: [a.cms.customername.artpro.co] => {"msg":
"keys/whitelabel_sites/a.coreapi.customername.enso_id_rsa.pub"}
TASK: [find out why the key isn't getting proper authorised 1 -- the
filename] ***
ok: [a.cms.customername.artpro.co] => {"msg": "$item"}
TASK: [find out why the key isn't getting proper authorised 2 -- the
file contents] ***
fatal: [a.cms.customername.artpro.co] => One or more undefined
variables: 'item' is undefined
FATAL: all hosts have already failed -- aborting
Both files keys/whitelabel_sites/a.coreapi.customername.enso_id_rsa.pub
and keys/javier exist, and can be accessed. In fact one of them is
created in the previous play, with the same variable templating.
I'm about to declare it a bug in ansible, and not in my playbook. If
anybody can either confirm or disabuse me, I'll appreciate it.
Thanks,
Javier