Hi Guys,
I got a playbook to deploy virtual machines and it´s working very well.
And now I´m trying to transfer and execute a shell script during the deploy of virtual machine but I´m getting many issues when changing the playbook.
Has anyone been faced this need as well?
Cheers,
Julio
racke
(Stefan Hornburg)
March 4, 2020, 7:04pm
2
Hi Guys,
I got a playbook to deploy virtual machines and it´s working very well.
And now I´m trying to transfer and execute a shell script during the deploy of virtual machine but I´m getting many
issues when changing the playbook.
Has anyone been faced this need as well?
It might be helpful to detail the changes and the issues your are seeing.
Regards
Racke
Hi Racke,
Thanks for the answer!
All configuration that I´ve been trying is based on this documentation:
https://docs.ansible.com/ansible/latest/modules/shell_module.html
Although I´m getting error the virtual machine is been created but without the copy and execution of shell script:
I just added the following lines in the playbook:
name: testing copy
copy:
src: /root/shell.sh
dest: /tmp
delegate_to: localhost
name: testing execute
shell: /tmp/shell.sh
This is my playbook:
A simple shell script only for testing:
Really appreciate any help.
Thanks in advance!
Julio
racke
(Stefan Hornburg)
March 5, 2020, 1:22pm
4
Hi Racke,
Thanks for the answer!
All configuration that I´ve been trying is based on this documentation:
https://docs.ansible.com/ansible/latest/modules/shell_module.html
Although I´m getting error the virtual machine is been created but without the copy and execution of shell script:
Ansible_error_1.PNG
I just added the following lines in the playbook:
- name: testing copy
copy:
src: /root/shell.sh
dest: /tmp
delegate_to: localhost
- name: testing execute
shell: /tmp/shell.sh
The error message states clearly "permission denied". Also there is no point the shell module for simple commands
as explained in the documentation.
Regards
Racke
Hi Racke ,
I moved the script to /tmp directory and also changed permission to 777.
In the playbook I just put:
name: testing
script: /tmp/shell.sh
The virtual machine is created with success and I figured out that the shell script is executed with success but in the localhost (ansible machine) instead of remote vm.
Do you know some way to hit the new virtual machine instead of localhost?
Kindly Regards,
Julio