问题原文
原帖链接 · Slava Fomin II · CC BY-SA 3.0
I'm using Ansible 1.6.6 to provision my machine.
There is a template task in my playbook that creates destination file from Jinja2 template:
tasks:
- template: src=somefile.j2 dest=/etc/somefile.conf
I do not want to replace somefile.conf if it already exists. Is it possible with Ansible? If so, how?
社区高分解答
原帖链接 · sanzante · CC BY-SA 4.0
You can just use the force param of the template module with force=no
tasks:
- name: Create file from template if it doesn't exist already.
template:
src: somefile.j2
dest: /etc/somefile.conf
force: no
From the Ansible template module docs:
force: the default is yes, which will replace the remote file when contents are different than the source. If no, the file will only be transferred if the destination does not exist.
Other answers use stat because the force parameter was added after they were written.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
