# Transfer execute and delete script python via playbook

**URL:** <https://forum.ansible.com/t/transfer-execute-and-delete-script-python-via-playbook/28233>\
**Category:** Ansible Project\
**Created:** [August 2, 2018, 8:21am UTC](https://forum.ansible.com/t/transfer-execute-and-delete-script-python-via-playbook/28233 "2018-08-02T08:21:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent\_Descargues](https://avatars.discourse-cdn.com/v4/letter/v/73ab20/32.png) [@Vincent\_Descargues](https://forum.ansible.com/u/Vincent_Descargues)\
**Post date:** [August 2, 2018, 8:21am UTC](https://forum.ansible.com/t/transfer-execute-and-delete-script-python-via-playbook/28233/1 "2018-08-02T08:21:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vaibhav\_kanchan](https://avatars.discourse-cdn.com/v4/letter/v/ce7236/32.png) [@vaibhav\_kanchan](https://forum.ansible.com/u/vaibhav_kanchan)\
**Post date:** [August 2, 2018, 9:41am UTC](https://forum.ansible.com/t/transfer-execute-and-delete-script-python-via-playbook/28233/2 "2018-08-02T09:41:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Drew\_Mullen](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@Drew\_Mullen](https://forum.ansible.com/u/Drew_Mullen)\
**Post date:** [August 2, 2018, 10:37am UTC](https://forum.ansible.com/t/transfer-execute-and-delete-script-python-via-playbook/28233/3 "2018-08-02T10:37:50Z")

</div>

You can do this using the ansible script module

[https://docs.ansible.com/ansible/2.5/modules/script\_module.html](https://docs.ansible.com/ansible/2.5/modules/script_module.html)

---

<div class="post-metadata">

**Author:** ![Drew\_Mullen](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@Drew\_Mullen](https://forum.ansible.com/u/Drew_Mullen)\
**Post date:** [August 2, 2018, 10:39am UTC](https://forum.ansible.com/t/transfer-execute-and-delete-script-python-via-playbook/28233/4 "2018-08-02T10:39:30Z")

</div>

You can do this using the ansible script module

[https://docs.ansible.com/ansible/2.5/modules/script\_module.html](https://docs.ansible.com/ansible/2.5/modules/script_module.html)

---

<div class="post-metadata">

**Author:** ![Vincent\_Descargues](https://avatars.discourse-cdn.com/v4/letter/v/73ab20/32.png) [@Vincent\_Descargues](https://forum.ansible.com/u/Vincent_Descargues)\
**Post date:** [August 2, 2018, 11:50am UTC](https://forum.ansible.com/t/transfer-execute-and-delete-script-python-via-playbook/28233/5 "2018-08-02T11:50:05Z")

</div>

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](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 :

```auto
- script: /etc/ansible/python.py --some-arguments 1234
  args:
    creates: /the/created/python.py

```

```auto
Or 

```

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [August 2, 2018, 2:31pm UTC](https://forum.ansible.com/t/transfer-execute-and-delete-script-python-via-playbook/28233/6 "2018-08-02T14:31:35Z")

</div>

Hi Vince,

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

```auto
https://github.com/ansible/ansible/blob/0461620b2ddc7e8c0bf00bf8b7b95edd3a4c109c/lib/ansible/plugins/action/script.py#L144

```
