Hi all,
can I run a command inside a playbook when finished the tasks?
.
Hi all,
can I run a command inside a playbook when finished the tasks?
.
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
http://docs.ansible.com/ansible/latest/shell_module.html
There are so-called < post tasks >. Search the documentation.
Hello Soniya,
Thanks for the link!
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
Thanks all
Both files SW1_show_run.txt and SW2_show_run.txt exist at the destination?
Also try giving full path to the files.
Fayad
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.
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
Hey, this error seems to generic, can you please provide more on this error?
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
Hi all,
I did fix the issue.
thanks all