-5

Could any provide me a better command than below

rsync -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l $USER `cat commandResult` "ansible-playbook --connection=local /home/ec2-user/ansible/plays/install.yml"
asur
  • 1,759
  • 7
  • 38
  • 81
  • 5
    What about using Ansible the way it was meant to be used, and run `ansible-playbook` on your local host but *target* the remote host? – larsks Dec 05 '18 at 18:48
  • @larsks I am executing the above command in Jenkinsfile declarative pipeline – asur Dec 06 '18 at 14:13

2 Answers2

6

It would be much easier to execute the playbook like ansible was intended to work, to get started you can create a file with the host you want to execute the playbook on, for example called 'hosts':

[webserver]
web1.hostname.example

Then in your playbook you can target this host/host group like so:

---
- hosts: webserver
  <<playbook contents here>>

Your ansible-playbook command will then look like this:

ansible-playbook -i hosts /home/ec2-user/ansible/plays/install.yml

If you want to ignore host key checking like you are in your ssh command, you can do this a number of ways as found in this stackoverflow question

A Random Guy
  • 167
  • 6
1
  ansible-playbook abc/plays/rme/install.yml -u $USER -i `cat commandResult`,
asur
  • 1,759
  • 7
  • 38
  • 81