我创建了一个ansible脚本,用于备份数据库,销毁,创建和指向备份到新创建的数据库:
- name: Backing up database
command: pg_dump --schema-only --file=image.dump.20100217 image
- name: Destroying Current Database
command: time dropdb image
- name: Creating Database
postgresql_db: name=image
owner='ryan'
- name: Pointing newly created DB to Backed up DB
command: psql image < image.dump.20100217
一切正常,直到它试图指向备份的数据库。 Ansible不处理<
符号并最终崩溃:
failed: [192.168.x.x] => {"changed": true, "cmd": ["psql", "image", "<", "image.dump.20100217"], "delta": "0:00:00.003229", "end": "2015-08-19 11:26:21.796224", "rc": 2, "start": "2015-08-19 11:26:21.792995", "warnings": []}
stderr: psql: warning: extra command-line argument "image.dump.20100217" ignored
psql: FATAL: role "<" does not exist
FATAL: all hosts have already failed -- aborting
有没有人对如何解决这个问题有任何建议?
答案 0 :(得分:1)
没有测试过,但有问题的角色的最终诀窍是将它放入Jinja表达式中:
command: psql image {{ "<" }} image.dump.20100217
我无法在Ansible 1.9.2中重现这一点。这是我测试的:
- command: echo psql image < image.dump.20100217
register: x
- debug: var=x
答案 1 :(得分:1)
使用模块'shell'而不是'command'
---
name: Pointing newly created DB to Backed up DB
shell: psql image < image.dump.20100217