ansible.builtin.shellにおいて使用されているshellを確認してみる
環境
- Fedora Linux 36 (Workstation Edition)
- ansible [core 2.11.6]
- ansible.cfg
[defaults]
verbosity = 1
stdout_callback = ansible.posix.debug
デフォルトで使用されているshellを確認する例
tasks
- shell: ps -elf | grep -w $$
TASK [shell] *****************************************************************************************************************************************************************
changed: [localhost] => {
"changed": true,
"cmd": "ps -elf | grep -w $$",
"delta": "0:00:00.029938",
"end": "2022-09-07 16:43:31.348422",
"rc": 0,
"start": "2022-09-07 16:43:31.318484"
}
STDOUT:
0 S hiroyuk+ 697087 697086 0 80 0 - 55758 do_wai 16:43 pts/5 00:00:00 /bin/sh -c ps -elf | grep -w $$
4 R hiroyuk+ 697088 697087 0 80 0 - 56790 - 16:43 pts/5 00:00:00 ps -elf
0 S hiroyuk+ 697089 697087 0 80 0 - 55578 pipe_r 16:43 pts/5 00:00:00 grep -w 697087
/bin/shが使用されている。
ただし、実行環境では/bin/shは/bin/bashへのシンボリックリンク。
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 1月 20 2022 /bin/sh -> bash
/bin/bashを指定して実行する例
tasks
- shell:
executable: "/bin/bash"
cmd: ps -elf | grep -w $$
TASK [shell] *****************************************************************************************************************************************************************
changed: [localhost] => {
"changed": true,
"cmd": "ps -elf | grep -w $$",
"delta": "0:00:00.030358",
"end": "2022-09-07 16:43:31.605923",
"rc": 0,
"start": "2022-09-07 16:43:31.575565"
}
STDOUT:
0 S hiroyuk+ 697106 697105 0 80 0 - 55758 do_wai 16:43 pts/5 00:00:00 /bin/bash -c ps -elf | grep -w $$
4 R hiroyuk+ 697107 697106 0 80 0 - 56790 - 16:43 pts/5 00:00:00 ps -elf
0 S hiroyuk+ 697108 697106 0 80 0 - 55578 pipe_r 16:43 pts/5 00:00:00 grep -w 697106
executableで指定した"/bin/bash"が利用されている。
参考
$ ansible-doc shell
> ANSIBLE.BUILTIN.SHELL (/home/hiroyukionodera/.local/lib/python3.10/site-packages/ansible/modules/shell.py)
The `shell' module takes the command name followed by a list of space-delimited arguments. Either a free form command or `cmd' parameter is
required, see the examples. It is almost exactly like the [ansible.builtin.command] module but runs the command through a shell (`/bin/sh') on
the remote node. For Windows targets, use the [ansible.windows.win_shell] module instead.
* note: This module has a corresponding action plugin.
OPTIONS (= is mandatory):
...
- cmd
The command to run followed by optional arguments.
[Default: (null)]
type: str
...
- executable
Change the shell used to execute the command.
This expects an absolute path to the executable.
[Default: (null)]
type: path
version_added: 0.9
version_added_collection: ansible.builtin
...