Ansibleでシェルコマンドを実行する

Ansibleでシェルコマンドを実行する

ディレクトリのみを変更するシェルスクリプトがあります(ディレクトリパスはここにあります)。

シェルファイル

#!/bin/bash
p="dir/file/create"
cd "$p"
exec bash

アンサーブルマニュアル

---
 - hosts: localhost
   gather_facts: true
   become: true
   become_user: oracle
   become_flags: 'content-ansible'
   tasks:
   - name: changing dir now..
     command: sh /dir/file/create/vars.sh

ANSIBLEでディレクトリパスを変更するためにシェルスクリプトを実行し、ディレクトリから後続のシェルファイル(#2)を実行したい(再度シェルスクリプト)。

Ansible PlayBookが完了しましたが、ディレクトリに入ってシェルスクリプトを実行できません(#2)。

ベストアンサー1

なぜ使わないの?chdir範囲?

chdir: コマンドを実行する前にディレクトリに cd

~から文書:

- name: Change the working directory to somedir/ before executing the command.
  command: somescript.sh
  args:
    chdir: somedir/

おすすめ記事