常用命令:

cmd: 用接要执行的命令
chdir: 切换目录

cat  shell.yaml
---
- hosts: node
  gather_facts: false
  become: yes
  become_method: sudo

一、切换到目录执行命令

  tasks:
    - name: '解压'
      shell:
        chdir: /data
        cmd: 'tar zxvf apache-tomcat-8.5.70.tar.gz'

二、执行多个命令,可用管道符 | 分开(不好用)

  tasks:
    - name:
      shell:
        cmd: |
          cd /home
          sh version.sh
          id
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐