Running ansible playbook in AWS EC2 instance using Jenkins Job from a local PC using ssh-agent

62 views
Skip to first unread message

Raj Boruah

unread,
Aug 4, 2016, 3:48:39 PM8/4/16
to Ansible Project
Hi,    

I am trying to run ansible playbook from jenkins installed in my local PC.    Ansible playbook is available in AWS EC2 instance. I am using ssh-agent plugin in     Jenkins to forward the ssh key but ansible is not able to ssh to EC2 instances.     Appreciate any help on it.    

Here is sample output the Jenkin's job run:    
Started by user RajB   
Building on master in workspace /data/jenkins/workspace   
**[ssh-agent] Using credentials ubuntu**   
[ssh-agent] Looking for ssh-agent implementation...   
[ssh-agent]   Java/JNR ssh-agent   
**[ssh-agent] Started.**   
SSH: Connecting from host [HP-Z420-Workstation]   
SSH: Connecting with configuration [aws-devops] ...   
SSH: Creating session: username [ubuntu], hostname [ec2-XXX.ap-southeast-   1.compute.amazonaws.com], port [22]   
SSH: Connecting session ...   
SSH: Connected   
SSH: Opening exec channel ...   
SSH: EXEC: channel open   
SSH: EXEC: STDOUT/STDERR from command [cd /home/ubuntu/.playbook && ansible-playbook ec2_facts.yml] ...   
SSH: EXEC: connected   

PLAY [verify ec2 facts] ********************************************************    

TASK [setup] *******************************************************************   
fatal: [x.x.1.116]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}   
fatal: [x.x.6.96]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}   
fatal: [x.x.12.51]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}   
to retry, use: --limit @ec2_facts.retry   

PLAY RECAP *********************************************************************   
x.x.1.116               : ok=0    changed=0    unreachable=1    failed=0   
x.x..10.157              : ok=0    changed=0    unreachable=1    failed=0   
x.x..12.51               : ok=0    changed=0    unreachable=1    failed=0   

SSH: EXEC: completed after 55,630 ms   
SSH: Disconnecting configuration [aws-devops] ...   
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [3]]   
Build step 'Send files or execute commands over SSH' changed build result to UNSTABLE   
[ssh-agent] Stopped.   
Notifying upstream projects of job completion   
Finished: UNSTABLE   
Reply all
Reply to author
Forward
0 new messages