Linux command inside ansible playbook

66 views
Skip to first unread message

Tcpip

unread,
Aug 27, 2017, 7:36:33 PM8/27/17
to Ansible Project
Hi all,

how can I run a linux command inside a playbook when in finished the tasks?


thanks

Soniya panwar

unread,
Aug 27, 2017, 11:19:12 PM8/27/17
to Ansible Project
you can use command module or shell module to execute any linux command inside a playbook.
for more details you can go through these links: http://docs.ansible.com/ansible/latest/command_module.html

Phonthip Namkaew

unread,
Aug 28, 2017, 2:12:34 AM8/28/17
to Ansible Project
There are so-called < post tasks >. Search the documentation.

Juraj Papic

unread,
Aug 28, 2017, 4:12:50 AM8/28/17
to ansible...@googlegroups.com
Hello Soniya,

Thanks for the link!



--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/cdLTpgsOluk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b1739573-47e3-4f75-8b38-31560c23e767%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Juraj A Papic

Juraj Papic

unread,
Aug 28, 2017, 4:48:30 AM8/28/17
to ansible...@googlegroups.com
Hi all,

I get the following error

fatal: [SW2]: FAILED! => {"changed": true, "failed": true, "rc": 2, "stderr": "diff: SW1_show_run.txt: No such file or directory\ndiff: SW2_show_run.txt: No such file or directory\n", "stdout": "", "stdout_lines": []}

This is my script
diff SW1_show_run.txt SW2_show_run.txt >> diff.txt

And this is how I add it to my plabook
- script: /Network_Automation_Ansible/backups/show_run/comp.sh

Thanks all

On Mon, Aug 28, 2017 at 3:12 AM, Phonthip Namkaew <phonthip...@gmail.com> wrote:
There are so-called < post tasks >. Search the documentation.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/cdLTpgsOluk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Juraj A Papic

Fayad

unread,
Aug 28, 2017, 4:58:14 AM8/28/17
to ansible...@googlegroups.com
Both files SW1_show_run.txt and SW2_show_run.txt exist at the destination?

Also try giving full path to the files.


Fayad

Sent from my OnePlus One

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-project+unsubscribe@googlegroups.com.

To post to this group, send email to ansible-project@googlegroups.com.

Juraj Papic

unread,
Aug 28, 2017, 4:59:57 AM8/28/17
to ansible...@googlegroups.com
Hello Fayad,

Yes they exist in the folder if I execute the script directly in the folder (sh diff.sh or bash diff.sh) it works.

thanks. 


For more options, visit https://groups.google.com/d/optout.



--

Juraj A Papic

Juraj Papic

unread,
Aug 28, 2017, 5:10:18 AM8/28/17
to ansible...@googlegroups.com
In the script I added the full path of both files and know i get this error

fatal: [SW1]: FAILED! => {"changed": true, "failed": true, "rc": 1, "stderr": "", "stdout": "", "stdout_lines": []}

Thanks
--

Juraj A Papic

Soniya panwar

unread,
Aug 28, 2017, 7:07:26 AM8/28/17
to Ansible Project
Hey, this error seems to generic, can you please provide more on this error?
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.



--

Juraj A Papic

--
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 post to this group, send email to ansible...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/cdLTpgsOluk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.



--

Juraj A Papic



--

Juraj A Papic

Juraj Papic

unread,
Aug 28, 2017, 8:15:32 AM8/28/17
to ansible...@googlegroups.com
its the only error i get this is the playbook I tried with script and with shell

 - name: Show Running Configuration
       register: show_run
       ios_command:
         commands:
          - show run
         provider: "{{ cli }}"
     - debug: var=show_run.stdout_lines

     - copy:
         content: "{{ show_run.stdout[0] }}"
         dest: "{{ backup_root }}/{{ inventory_hostname }}_show_run.txt"

     - name: Compare
       script: /Network_Automation_Ansible/backups/show_run/./comp.sh


To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b35b6544-03fe-4048-9dbe-5ddfa375e87a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Juraj A Papic

Juraj Papic

unread,
Aug 28, 2017, 9:27:00 AM8/28/17
to ansible...@googlegroups.com
Hi all,

I did fix the issue.

thanks all
--

Juraj A Papic
Reply all
Reply to author
Forward
0 new messages