나는'm를 사용하 Ansible1.6.6
을 제공 내 기계입니다.
가 있[템플릿 작업][드 템플릿에서는 각본을 만드는 목적지에서 파일 Jinja2 템플릿:
tasks:
- template: src=somefile.j2 dest=/etc/somefile.conf
내가 원하지 않을 바꾸기somefile.conf
는 경우 그것은 이미 있습니다. 그것은으로 가능한 Ansible? 그렇다면,어떻게 합니까?
당신이 사용할 수 있습니다forceparam 템플릿의 모듈:
tasks:
- template: src=somefile.j2 dest=/etc/somefile.conf force=no
이름을 지정하는 작업;-)
tasks:
- name: Create file from template if it doesn't exist already.
template:
src: somefile.j2
dest:/etc/somefile.conf
force: no
에서Ansible 템플릿 모듈docs:
군:기본값은 yes,는 것이 대체하는 원격 경우 파일 내용은 다른 소스입니다. 지 않는 경우,파일만 로 전송하는 경우 목적지는 존재하지 않습니다.
다른 답변을 사용하통계
기 때문에력매개변수를 추가한 후 그들은 기록됩니다.
당사는 대상 파일이 있거나지 않고 다음에 기초하여 결정을 내리는 출력의 it's 결과입니다.
tasks:
- name: Check that the somefile.conf exists
stat:
path: /etc/somefile.conf
register: stat_result
- name: Copy the template, if it doesnt exist already
template:
src: somefile.j2
dest: /etc/somefile.conf
when: stat_result.stat.exists == False