Transfer execute and delete script python via playbook

38 views
Skip to first unread message

Vincent Descargues

unread,
Aug 2, 2018, 4:21:05 AM8/2/18
to Ansible Project
Hello, 

I would like to know how it is possible with a command to be able to both transfer execute and delete a python script via a playbook. Currently I do it in 3 lines: 1) Transfer 2) Execute 3) Delete.

I could see on different forum that we could use the function "script"


My current playbook :
hosts: host
- name: download python script
copy:
src: /etc/ansible/xxxx/python.py
dest: /etc/sssd/
- name: execute python script
command: python /etc/sssd/python.py
- name: delete python script
command: rm /etc/sssd/python.py




In fact, I would like to be able to transfer the python script, execute it and delete it because I do not want to store it on the machine where it runs.


(example command "script" find on internet) I tried it but it does not work :

- hosts: my-servers sudo: true tasks: - script: /home/stuart/scripts/setup.sh --creates /home/stuart/installed-git.txt

Thanks a lot for answer.

Vincent

vaibhav kanchan

unread,
Aug 2, 2018, 5:42:09 AM8/2/18
to ansible...@googlegroups.com
Try to put the steps in shell script..like copy the python script to the server ..change the permission of the script..execute it..once the exit status s 0..delete the script..you can use 2 modules..copy  and shell 

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e30763d9-2512-4966-b04d-53daad94af8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vincent Descargues

unread,
Aug 2, 2018, 7:50:16 AM8/2/18
to ansible...@googlegroups.com
Hi Vaibhav,

I use already this 2 modules, but i just want use only one module 'maybe "script module"' like that https://docs.ansible.com/ansible/2.5/modules/script_module.html

I think the only native module of ansible to do this is "script"
Like this maybe :
- script: /etc/ansible/python.py --some-arguments 1234
  args:
    creates: /the/created/python.py
Or 
- script: /etc/ansible/python.py --some-arguments 1234
args: removes: /etc/ansible/python.py

but there is no execution in this order finally I think ....


2018-08-02 11:41 GMT+02:00 vaibhav kanchan <vaibhav...@gmail.com>:
Try to put the steps in shell script..like copy the python script to the server ..change the permission of the script..execute it..once the exit status s 0..delete the script..you can use 2 modules..copy  and shell 
On Aug 2, 2018 13:51, "Vincent Descargues" <vdesc...@gmail.com> wrote:
Hello, 

I would like to know how it is possible with a command to be able to both transfer execute and delete a python script via a playbook. Currently I do it in 3 lines: 1) Transfer 2) Execute 3) Delete.

I could see on different forum that we could use the function "script"


My current playbook :
hosts: host
- name: download python script
copy:
src: /etc/ansible/xxxx/python.py
dest: /etc/sssd/
- name: execute python script
command: python /etc/sssd/python.py
- name: delete python script
command: rm /etc/sssd/python.py




In fact, I would like to be able to transfer the python script, execute it and delete it because I do not want to store it on the machine where it runs.


(example command "script" find on internet) I tried it but it does not work :

- hosts: my-servers sudo: true tasks: - script: /home/stuart/scripts/setup.sh --creates /home/stuart/installed-git.txt

Thanks a lot for answer.

Vincent

--
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.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAHKdPz5AGLQgM6bBWHETjjdvswWYeqkEQ7KM2kc4CmGORohhGQ%40mail.gmail.com.

Varun Chopra

unread,
Aug 2, 2018, 10:31:35 AM8/2/18
to Ansible Project
Hi Vince,

script will delete your script on it's own after executing it, similar to other modules.

Drew Mullen

unread,
Aug 16, 2018, 11:57:33 PM8/16/18
to Ansible Project
You can do this using the ansible script module

https://docs.ansible.com/ansible/2.5/modules/script_module.html

Drew Mullen

unread,
Aug 16, 2018, 11:57:33 PM8/16/18
to Ansible Project
Reply all
Reply to author
Forward
0 new messages