使用ansible-playbook中使用shell模块 执行多条命令
时间: 2024-06-04 21:13:17 浏览: 40
可以在 playbook 中使用 shell 模块执行多条命令,命令之间用 && 连接,例如:
- name: Execute multiple commands using shell module
shell: command1 && command2 && command3
也可以将多个命令写在一个 shell 脚本中,然后使用 shell 模块执行该脚本,例如:
- name: Execute shell script using shell module
shell: /path/to/script.sh
相关问题
使用ansible-playbook中使用shell模块 执行 shell 脚本
我可以帮你解答这个问题。使用ansible-playbook中的shell模块可以执行shell脚本,示例代码如下:
```
- name: Execute shell script using shell module
shell: /path/to/your/script.sh
```
请注意,您需要将`/path/to/your/script.sh`替换为实际的shell脚本路径。希望这可以帮助你!
使用ansible-playbook 切换用户 执行shell命令
可以直接使用以下命令:
```
ansible <host> -u <username> -b -a "<command>"
```
其中,`<host>`为目标主机名或IP,`<username>`为要切换到的用户名,`<command>`为要执行的命令,例如:
```
ansible host1 -u deploy -b -a "ls /root"
```
这条命令会切换到`deploy`用户,使用超级用户权限列出`/root`目录下的所有文件。