# Executing ansible through SSH

**URL:** <https://forum.ansible.com/t/executing-ansible-through-ssh/38299>\
**Category:** Ansible Project\
**Created:** [August 4, 2023, 10:25am UTC](https://forum.ansible.com/t/executing-ansible-through-ssh/38299 "2023-08-04T10:25:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [August 4, 2023, 10:25am UTC](https://forum.ansible.com/t/executing-ansible-through-ssh/38299/1 "2023-08-04T10:25:43Z")

</div>

Hi ,

I have 3 servers serverA ,serverB , and serverC.  
From serverA , I am trying to execute the playbook on serverB which is the control node(Where ansible is available).

The playbook when run from serverB(login with ssh) with executing as below works fine and got the expected output.

# export ANSIBLE\_HOST\_KEY\_CHECKING=False

# ansible-playbook /home/ansible/playbook1.yml --limit serverC --key-file /home/ansible/priv\_key.file

The playbook has “become: true”

From ServerA , I am executing the below command using a bash script and the script works. But the execution is not happening

#!/bin/bash  
ssh -i .ssh/serverb\_key root@serverB “export ANSIBLE\_HOST\_KEY\_CHECKING=False; ansible-playbook /home/ansible/playbook1.yml --limit serverC --key-file /home/ansible/priv\_key.file”

The requirement is to initiate the script from serverA - which will execute the playbook in serverB and do the changes in serverC.  
I even try with the “&” at the end to execute the ansible-playbook in the background ..but still the same result. "“export ANSIBLE\_HOST\_KEY\_CHECKING=False; ansible-playbook /home/ansible/playbook1.yml --limit serverC --key-file /home/ansible/priv\_key.file &”

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [August 4, 2023, 10:44am UTC](https://forum.ansible.com/t/executing-ansible-through-ssh/38299/2 "2023-08-04T10:44:20Z")

</div>

Try removing the semi colon after false

---

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [August 4, 2023, 12:10pm UTC](https://forum.ansible.com/t/executing-ansible-through-ssh/38299/3 "2023-08-04T12:10:17Z")

</div>

Thanks … its working now

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [August 4, 2023, 2:30pm UTC](https://forum.ansible.com/t/executing-ansible-through-ssh/38299/4 "2023-08-04T14:30:33Z")

</div>

If that is true, then you can probably also remove the "export " bit.  
So:

ssh -i .ssh/serverb\_key root@serverB  
"ANSIBLE\_HOST\_KEY\_CHECKING=False ansible-playbook  
/home/ansible/playbook1.yml --limit serverC --key-file  
/home/ansible/priv\_key.file"
