Debian Codegraph @

lib/ansible/modules/raw.py

raw
1 # This is a virtual module that is entirely implemented server side
2
3 # Copyright: (c) 2012, Ansible Project
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import annotations
7
8
9 DOCUMENTATION = r"""
10 ---
11 module: raw
12 short_description: Executes a low-down and dirty command
13 version_added: historical
14 options:
15 free_form:
16 description:
17 - The raw module takes a free form command to run.
18 - There is no parameter actually named 'free form'; see the examples!
19 required: true
20 executable:
21 description:
22 - Change the shell used to execute the command. Should be an absolute path to the executable.
23 - When using privilege escalation (C(become)) a default shell will be assigned if one is not provided
24 as privilege escalation requires a shell.
25 version_added: "1.0"
26 description:
27 - Executes a low-down and dirty SSH command, not going through the module
28 subsystem.
29 - This is useful and should only be done in a few cases. A common
30 case is installing C(python) on a system without python installed by default.
31 Another is speaking to any devices such as
32 routers that do not have any Python installed. In any other case, using
33 the M(ansible.builtin.shell) or M(ansible.builtin.command) module is much more appropriate.
34 - Arguments given to C(raw) are run directly through the configured remote shell.
35 - Standard output, error output and return code are returned when
36 available.
37 - There is no change handler support for this module.
38 - This module does not require python on the remote system, much like
39 the M(ansible.builtin.script) module.
40 - This module is also supported for Windows targets.
41 - If the command returns non UTF-8 data, it must be encoded to avoid issues. One option is to pipe
42 the output through C(base64).
43 extends_documentation_fragment:
44 - action_common_attributes
45 - action_common_attributes.raw
46 attributes:
47 check_mode:
48 support: none
49 diff_mode:
50 support: none
51 platform:
52 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
53 platforms: all
54 raw:
55 support: full
56 notes:
57 - "If using raw from a playbook, you may need to disable fact gathering
58 using C(gather_facts: no) if you're using C(raw) to bootstrap python
59 onto the machine."
60 - If you want to execute a command securely and predictably, it may be
61 better to use the M(ansible.builtin.command) or M(ansible.builtin.shell) modules instead.
62 - The C(environment) keyword does not work with raw normally, it requires a shell
63 which means it only works if C(executable) is set or using the module
64 with privilege escalation (C(become)).
65 seealso:
66 - module: ansible.builtin.command
67 - module: ansible.builtin.shell
68 - module: ansible.windows.win_command
69 - module: ansible.windows.win_shell
70 author:
71 - Ansible Core Team
72 - Michael DeHaan
73 """
74
75 EXAMPLES = r"""
76 - name: Bootstrap a host without Python installed
77 ansible.builtin.raw: dnf install -y python3 python3-libdnf
78
79 - name: Run a command that uses non-posix shell-isms (in this example /bin/sh doesn't handle redirection and wildcards together but bash does)
80 ansible.builtin.raw: cat < /tmp/*txt
81 args:
82 executable: /bin/bash
83
84 - name: Safely use templated variables. Always use quote filter to avoid injection issues.
85 ansible.builtin.raw: "{{ package_mgr|quote }} {{ pkg_flags|quote }} install {{ python|quote }}"
86
87 - name: List user accounts on a Windows system
88 ansible.builtin.raw: Get-WmiObject -Class Win32_UserAccount
89 """