2017-07-07 19 views
0

私のgitリソースからフェッチされたpostgresql sqlを実行します。 ansible script.Thisでの入力が正常に実行されるスクリプト上記の私の完全なansibleスクリプト実行中のpostgres sqlスクリプトを実行できません

- hosts: "{{ HOST }}" 
    become: true 
    become_user: "admin" 
    become_method: su 
    gather_facts: true 
    vars: 
    app_path: "{{ app_path }}" 
    app_dir: "{{ app_dir }}" 

    tasks: 
    - stat: 
     path: "{{ app_path }}/{{ app_dir }}" 
     register: exist 

    - name: create "{{ app_path }}/{{ app_dir }}" directory 
     file: dest="{{ app_path }}/{{ app_dir }}" state=directory 
     when: exist.stat.exists != True 


    - git: 
     repo: http://git-url/postgres-demo.git 
     dest: "{{ app_path }}/{{ app_dir }}" 
     version: "{{ GIT_TAG }}" 
     refspec: '+refs/heads/{{ GIT_TAG }}:refs/remotes/origin/{{ GIT_TAG }}' 
     update: yes 
     force: true 
     register: cloned 

    - name: Execute postgres dump files 
     shell: "/usr/bin/psql -qAtw -f {{ item }}" 
     with_fileglob: 
      - "{{ app_path }}/{{ app_dir }}/{{ scripts_dir }}/*" 
     register: postgres_sql 
     become: true 
     become_user: "postgres" 
     become_method: su 

あるよう 私は最初のgitリポジトリからすべてのスクリプトを取得したいと、私は取って特定のディレクトリからスクリプトを実行したいですしかし、Postgresのステップは衰退以下の私を投げ:私は私のPostgreSQLのDBを確認

[WARNING]: Unable to find '/home/admin/postgres-dev/test' in expected paths. 

は、私は、私は、このスクリプトを使用して作成するテーブルを見つけることができません。

答えて

1

Ansibleのすべてのルックアップは、ローカルで実行されます。だから、

with_fileglob: 
    - "{{ app_path }}/{{ app_dir }}/{{ scripts_dir }}/*" 

は、ローカルホスト上のファイルを検索しfileglobのルックアップを使用しています!

最初にfindモジュールを使用して、必要なすべてのスクリプトを検索し、その出力を登録し、スクリプトを実行するために登録済み変数にwith_itemsでループするようにこのコードをリファクタリングする必要があります。

関連する問題