Hi,
Ansible: 1.3.2
I have a question related how ansible is working with know hosts.
I am trying run ansible from jenkins on local VMs managed by vagrant.
When I’ve run my playbook from jenkins - I’ve started having this error:
=== Setup build hosts ===
+ Run ansible
ansible-playbook -vvv -i inventory/hosts_ossl_vms ossl-buildservers.yml
PLAY [OSSL-Build | Configure build hosts] *************************************
GATHERING FACTS ***************************************************************
<192.168.79.253> ESTABLISH CONNECTION FOR USER: vagrant on PORT 22 TO 192.168.79.253
fatal: [ossl-test2] => {'msg': "FAILED: (22, 'Invalid argument')", 'failed': True}
TASK: [OSSL-Common | Create folders for configuration] ************************
FATAL: no hosts matched or all hosts have already failed -- aborting
I’ve started investigating what is wrong, and these is result:
- Copy know hosts to /etc/ssh/ssh_known_hosts
Inventory file:
ossl-test2 ansible_ssh_host=192.168.79.253 ansible_ssh_private_key_file=keys/vagrant ansible_connection=ssh
- Connection from SSH:
ssh -i keys/vagrant -l vagrant 192.168.79.253
Last login: Thu Oct 24 00:27:49 2013 from 192.168.79.254
[vagrant@ossl-test2 ~]$
----> So everything is working well.
- Connection via ansible and forcing using GlobalKnowHosts
ANSIBLE_SSH_ARGS=“-o GlobalKnownHostsFile=/etc/ssh/ssh_known_hosts” make setup-build-hosts OPTARG=“-vvv”
=== Setup build hosts ===
- Run ansible
ansible-playbook -vvv -i inventory/hosts_ossl_vms ossl-buildservers.yml
PLAY [OSSL-Build | Configure build hosts] *************************************
GATHERING FACTS ***************************************************************
<192.168.79.253> ESTABLISH CONNECTION FOR USER: vagrant
<192.168.79.253> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘GlobalKnownHostsFile=/etc/ssh/ssh_known_hosts’, ‘-o’, ‘Port=22’, ‘-o’, ‘IdentityFile=keys/vagrant’, ‘-o’, ‘KbdInteract
iveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=vagrant’, ‘-o’,
‘ConnectTimeout=10’, ‘192.168.79.253’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-1382571109.18-256034745979242 && chmod a+rx $HOME/.ansible/tmp/ansible-13825711
09.18-256034745979242 && echo $HOME/.ansible/tmp/ansible-1382571109.18-256034745979242’”]
previous known host file not found
Message: - previous know hosts not found is displayed - but not error reported.
Run ansible without any options for SSH - causing that ansible is asking for SSH Key (displaying prompt - yes / no). IMHO should read global known_hosts file
Creating file /var/lib/jenking/.ssh/known_hosts allowed jenkins work without any problems.
Summary:
- It looks like ansible is not reading global SSH known hosts files (when connection setup to ssh or paramiko)
- It looks that passing option for ssh related with global knowhosts generate message: previous known host file not found - but connection can’t be established with hosts.
Goal:
- Use ansible under jenkins without adding manually know hosts to jenkins users - just by creating global known hosts or by passing SSH parameters related with KnownHosts
Best regards,
Marcin Praczko