Executing ansible through SSH

36 views
Skip to first unread message

Veera

unread,
Aug 4, 2023, 6:25:43 AM8/4/23
to Ansible Project
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 &"











Dick Visser

unread,
Aug 4, 2023, 6:44:49 AM8/4/23
to ansible...@googlegroups.com
Try removing the semi colon after false 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/591279df-3595-477f-a30f-dc86a4ea5959n%40googlegroups.com.
--
Sent from Gmail Mobile

Veera

unread,
Aug 4, 2023, 8:10:17 AM8/4/23
to Ansible Project
Thanks .. its working now

Dick Visser

unread,
Aug 4, 2023, 10:31:07 AM8/4/23
to ansible...@googlegroups.com
On Fri, 4 Aug 2023 at 14:10, Veera <svee...@gmail.com> wrote:
>
> Thanks .. its working now

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

ssh -i .ssh/serverb_key root@serverB
Reply all
Reply to author
Forward
0 new messages