Hi,
How do I get the local user in an variable? My usercase:
- name: Make sure my authorized key is installed
authorized_key: user=${USER} key=“{{ lookup(‘file’, ‘/home/’ + $USER + ‘/.ssh/id_rsa.pub’) }}”
Thanks,
Mathias
Hi,
How do I get the local user in an variable? My usercase:
Thanks,
Mathias
How do I get the local user in an variable? My usercase:
Look for the ENV lookup: $ENV(USER)
-JP
Thanks! But it fails:
msg: Failed to lookup user ${ENV(USER)}: ‘getpwnam(): name not found: ${ENV(USER)}’
failed: [hdata01] => {“failed”: true, “item”: “”}
Any idea?
It works like this:
authorized_key: user=$ENV(USER) key=“{{ lookup(‘file’, ‘/home/’ + $ENV(USER) + ‘/.ssh/id_rsa.pub’) }}”
but the key doesn’t evaluate. The lookup doesn’t work. My remote file contains
{{lookup(‘file’, ‘/home/’ + mathias + ‘/.ssh/id_rsa.pub’)}}
?
msg: Failed to lookup user ${ENV(USER)}: 'getpwnam(): name not found:
${ENV(USER)}'
failed: [hdata01] => {"failed": true, "item": ""}
getpwnam() failed?! Is this a Unix system you're running on?
What OS/version?
Can you try
- local_action: debug msg="Hello $ENV(HOME)"
and run ansible-playbook -vvv
-JP
Yeah, it’s an Ubuntu 12.10.
But it works like this:
authorized_key: user=$ENV(USER) key=“{{ lookup(‘file’, ‘/home/’ + $ENV(USER) + ‘/.ssh/id_rsa.pub’) }}”
but the key doesn’t evaluate. The lookup doesn’t work. My remote authorized_keys now contains
{{lookup(‘file’, ‘/home/’ + mathias + ‘/.ssh/id_rsa.pub’)}}
which doesn’t work…
This works:
Thanks!!
Friendly reminder:
$ENV(USER) as a mechanism of getting lookup plugins is deprecated
We should be instructing folks do to:
{{ lookup(‘env’, ‘USER’) }}
Hi! For me it doesn’t!
Neither this:
authorized_key: user=$ENV(USER) key=“{{ lookup(‘file’, ‘~/.ssh/id_rsa.pub’) }}”
nor this:
authorized_key: user={{ lookup(‘env’, ‘USER’) }} key=“{{ lookup(‘file’, ‘~/.ssh/id_rsa.pub’) }}”
both fail with:
failed: [dev] => {“failed”: true, “item”: “”}
msg: Failed to lookup user patte: ‘getpwnam(): name not found: patte’
I’m patte on OSX, with ansible 1.5.5 fired by vagrant provision
any idea?
This seems unrelated and you’re replying to an old thread, but please try this on Ansible 1.6 (so you’re using a recently released version) and give us some steps to reproduce this, perhaps.
Thanks!