Debian Codegraph @

lib/ansible/modules/script.py

raw
1 # Copyright: (c) 2012, Ansible Project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3
4 from __future__ import annotations
5
6
7 DOCUMENTATION = r"""
8 ---
9 module: script
10 version_added: "0.9"
11 short_description: Runs a local script on a remote node after transferring it
12 description:
13 - The M(ansible.builtin.script) module takes the script name followed by a list of space-delimited arguments.
14 - Either a free-form command or O(cmd) parameter is required, see the examples.
15 - The local script at the path will be transferred to the remote node and then executed.
16 - The given script will be processed through the shell environment on the remote node.
17 - This module does not require Python on the remote system, much like the M(ansible.builtin.raw) module.
18 - This module is also supported for Windows targets.
19 options:
20 free_form:
21 description:
22 - Path to the local script file followed by optional arguments.
23 type: str
24 cmd:
25 type: str
26 description:
27 - Path to the local script to run followed by optional arguments.
28 creates:
29 description:
30 - A filename on the remote node, when it already exists, this step will B(not) be run.
31 version_added: "1.5"
32 type: str
33 removes:
34 description:
35 - A filename on the remote node, when it does not exist, this step will B(not) be run.
36 version_added: "1.5"
37 type: str
38 chdir:
39 description:
40 - Change into this directory on the remote node before running the script.
41 version_added: "2.4"
42 type: str
43 executable:
44 description:
45 - Name or path of an executable to invoke the script with.
46 version_added: "2.6"
47 type: str
48 notes:
49 - It is usually preferable to write Ansible modules rather than pushing scripts. Convert your script to an Ansible module for bonus points!
50 - The P(ansible.builtin.ssh#connection) connection plugin will force pseudo-tty allocation via C(-tt) when scripts are executed.
51 Pseudo-ttys do not have a stderr channel and all stderr is sent to stdout. If you depend on separated stdout and stderr result keys,
52 please switch to a set of tasks that comprises M(ansible.builtin.copy) with M(ansible.builtin.command) instead of using M(ansible.builtin.script).
53 - If the path to the local script contains spaces, it needs to be quoted.
54 - This module is also supported for Windows targets.
55 - If the script returns non-UTF-8 data, it must be encoded to avoid issues. One option is to pipe
56 the output through C(base64).
57 - This module will automatically unvault the script.
58 seealso:
59 - module: ansible.builtin.shell
60 - module: ansible.windows.win_shell
61 author:
62 - Ansible Core Team
63 - Michael DeHaan
64 extends_documentation_fragment:
65 - action_common_attributes
66 - action_common_attributes.files
67 - action_common_attributes.raw
68 attributes:
69 check_mode:
70 support: partial
71 details: while the script itself is arbitrary and cannot be subject to the check mode semantics it adds O(creates)/O(removes) options as a workaround
72 diff_mode:
73 support: none
74 platform:
75 details: This action is one of the few that requires no Python on the remote as it passes the command directly into the connection string
76 platforms: all
77 raw:
78 support: full
79 safe_file_operations:
80 support: none
81 vault:
82 support: full
83 """
84
85 EXAMPLES = r"""
86 - name: Run a script with arguments (free form)
87 ansible.builtin.script: /some/local/script.sh --some-argument 1234
88
89 - name: Run a script with arguments (using 'cmd' parameter)
90 ansible.builtin.script:
91 cmd: /some/local/script.sh --some-argument 1234
92
93 - name: Run a script only if file.txt does not exist on the remote node
94 ansible.builtin.script: /some/local/create_file.sh --some-argument 1234
95 args:
96 creates: /the/created/file.txt
97
98 - name: Run a script only if file.txt exists on the remote node
99 ansible.builtin.script: /some/local/remove_file.sh --some-argument 1234
100 args:
101 removes: /the/removed/file.txt
102
103 - name: Run a script using an executable in a non-system path
104 ansible.builtin.script: /some/local/script
105 args:
106 executable: /some/remote/executable
107
108 - name: Run a script using an executable in a system path
109 ansible.builtin.script: /some/local/script.py
110 args:
111 executable: python3
112
113 - name: Run a Powershell script on a Windows host
114 script: subdirectories/under/path/with/your/playbook/script.ps1
115 """