<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 執行命令模塊 [shell][1] 和 command 這兩個模塊都用來執行命令,shell的范圍更大,支持腳本和管道,因此推薦使用shell。 >[info] -m 指定模塊 module > -a 指定參數 args 當參數為沒有空格隔開的內容時,可以不使用引號(單引號/雙引號都可以);否則要使用引號。 ### 選項 ``` chdir change dir creates a filename, when it already exists, this step will not be run. removes a filename, when it does not exist, this step will not be run. warn no yes ``` ### 返回結果 ![](https://box.kancloud.cn/d47ca564dff3cabd930636b630c4be33_606x261.png) ### 命令行使用格式 ``` ansible anserver -m command -a 'hostname' ansible anserver -m shell -a 'hostname' ``` ### 腳本的遠程執行 先使用copy模塊復制腳本到遠程客戶端,再使用shell模塊執行 ``` # ansible anserver -m shell -a '/tmp/test.sh' 若文件無執行權限,則可使用以下 # ansible anserver -m shell -a '/bin/bash /tmp/test.sh' ``` ### 在playbook中使用格式 ``` --- - name: shell and command test hosts: s.hi.com tasks: - name: shell test shell: hostname - name: command test command: hostname ``` ### 補充 當不指定模塊時,默認使用`command`模塊 `ansible hostname -a 'hostname'` ## 示例 ~~~ # 使用args來執行一些選項 - name: This command will change the working directory to somedir/ and will only run when somedir/somelog.txt doesn't exist. shell: somescript.sh >> somelog.txt args: chdir: somedir/ creates: somelog.txt executable: /bin/bash # /bin/sh不能同時處理重定向和通配符操作,使用/bin/bash可以 - 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) shell: cat < /tmp/*txt args: executable: /bin/bash # 在另一個解釋器下執行 - name: Run expect to wait for a successful PXE boot via out-of-band CIMC shell: | set timeout 300 spawn ssh admin@{{ cimc_host }} expect "password:" send "{{ cimc_password }}\n" expect "\n{{ cimc_name }}" send "connect host\n" expect "pxeboot.n12" send "\n" exit 0 args: executable: /usr/bin/expect delegate_to: localhost ~~~ [1]:http://docs.ansible.com/ansible/shell_module.html
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看