【发布时间】:2017-07-07 15:33:00
【问题描述】:
我想执行一个从我的 git 资源中获取的 postgresql sql。 我想首先从 git 存储库中获取所有脚本,然后想从特定目录执行脚本,我将其作为 ansible 脚本的输入。这是我完整的 ansible 脚本
- 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
上述脚本已成功执行,但 postgres 步骤在减弱后抛出了我:
[WARNING]: Unable to find '/home/admin/postgres-dev/test' in expected paths.
当我检查我的 postgresql 数据库时,我没有找到要使用此脚本创建的表。
【问题讨论】:
标签: postgresql ansible