Ansible: Need to understand how can we use scp and ssh command with shell or script.

1,578 views
Skip to first unread message

nishant bawane

unread,
Apr 18, 2017, 12:25:26 PM4/18/17
to Ansible Project
for i in `cat /tmp/list`
        do
        echo $i
        scp HLC_auth $i:.ssh/authorized_keys
        scp known_hosts.LLC $i:.ssh/known_hosts
        ssh $i "rm -rf .ssh/id_dsa*"
        ssh $i "ssh-keygen -d"
        done
Above the the task i need to run through playbook, please suggest how the playbook should look alike.


below is the code which run succesfully when i exclude scp and ssh commands -

 shell: for i in `cat /home/dp794d/temp/list`;
                do echo $i;
                done

Need to include the scp and ssh command also under the same shell.. how to perform that task.

Kai Stian Olstad

unread,
Apr 18, 2017, 1:04:20 PM4/18/17
to ansible...@googlegroups.com
There is many ways to do this, but you should probably start with the
script module until you get some experience with Ansible
https://docs.ansible.com/ansible/script_module.html

--
Kai Stian Olstad

nishant bawane

unread,
Apr 18, 2017, 1:39:26 PM4/18/17
to Ansible Project, ansible-pr...@olstad.com

--------------


I tried using script module to run the single scp command, but it is not working.


My script file(abc.sh) contains below scp command -

#!/bin/bash

 scp /home/capio/ansible/pmossWipm/day1/playbooks/xyz.yml a...@130.6.50.131:/home/user

My YML Looks like below -

---
- hosts: testserver
  tasks:

   - name: "run the script"
     script: /home/capio/ansible/pmossWipm/day1/scripts/abc.sh
-----------------------------------------------------------------------------------------------------------------------------------------------

Error getting is as per below-


It is getting stuck here only and hence not proceeding.

Please suggest what exactly needs to be done!

Auto Generated Inline Image 1

Kai Stian Olstad

unread,
Apr 19, 2017, 1:29:24 PM4/19/17
to ansible...@googlegroups.com
On 18. april 2017 19:39, nishant bawane wrote:
> I tried using script module to run the single scp command, but it is not
> working.
>
>
> My script file(abc.sh) contains below scp command -
>
> #!/bin/bash
>
> scp /home/capio/ansible/pmossWipm/day1/playbooks/xyz.yml
> a...@130.6.50.131:/home/user
>
> My YML Looks like below -
>
> ---
> - hosts: testserver
> tasks:
>
> - name: "run the script"
> script: /home/capio/ansible/pmossWipm/day1/scripts/abc.sh
> -----------------------------------------------------------------------------------------------------------------------------------------------
>
> Error getting is as per below-
>
>
> It is getting stuck here only and hence not proceeding.
>
> Please suggest what exactly needs to be done!

This is not a Ansible problem, so you might have better luck in a more
bash/shell/ssh related community.

The only hint I will give you is to make that work you would need
passwordless ssh keys in place.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages