Want to use private_key_file as varable in template file.

349 views
Skip to first unread message

t goto

unread,
May 7, 2015, 10:51:37 PM5/7/15
to ansible...@googlegroups.com
Hello.
I want to use `private_key_file` in ansible.cfg as a variable in template file.

Say, I have ansible.cfg like this..
[defaults]
hostfile
= hosts
remote_user
= ubuntu
private_key_file
= /home/test/.ssh/id_rsa


And want to use it in Jinja2 format like this..
options[:user] ||= Etc.getlogin
options
[:keys] = "{{ private_key_file }}"
# options[:keys] = "/home/test/.ssh/id_rsa"


with playbook calls template modules..
- name: template copy
 
template: src=spec.j2 dest=/serverspec/.spec



If you use `ansible_ssh_private_key_file` in inventory host file, you can successfuly template it.
But I  want to use good old ansible.cfg.
Any ideas?

Brian Coca

unread,
May 8, 2015, 10:46:28 AM5/8/15
to ansible...@googlegroups.com
something like:
lookup('pipe', 'grep private_key_file /etc/ansible/ansible.cfg|cut -f2 -d"="')


--
Brian Coca

t goto

unread,
May 9, 2015, 1:36:13 AM5/9/15
to ansible...@googlegroups.com
Sounds like a plan! :)
I willl try this method, thanks!

2015年5月8日金曜日 23時46分28秒 UTC+9 Brian Coca:

Marcus Franke

unread,
May 10, 2015, 4:51:32 PM5/10/15
to ansible...@googlegroups.com


Am 09.05.2015 07:36 schrieb "t goto" <tomoy...@gmail.com>:
>
> Sounds like a plan! :)
> I willl try this method, thanks!
>

Hi,

one thing I don't understand, why do you need to roll out the private key at all? Using the ssh-agent and agent forwarding you can use your locally stored private key even for those hosts in the second row behind some kind of jump host.

Regards,
Marcus

t goto

unread,
May 10, 2015, 8:39:41 PM5/10/15
to ansible...@googlegroups.com
Hello, Marcus.

What I'm trying to do is to use `serverspec` to test the ansible-deployed hosts.
As `serverspec` connects to test machines via ssh, I have to let it know the location of ssh private key.
I didn't want to edit the root .ssh/config for such small part, I was looking for a way to specify private key.

Thank you.

---
t goto


2015年5月11日月曜日 5時51分32秒 UTC+9 Marcus Franke:
Reply all
Reply to author
Forward
0 new messages