New option onlyifnotexist to only create the file when it doesn't already exists

This commit is contained in:
nemunaire 2023-03-15 01:00:54 +01:00
parent b35c5b370f
commit 3d79f8b747
1 changed files with 10 additions and 0 deletions

View File

@ -1,8 +1,18 @@
---
- name: check if the config already exists
ansible.builtin.stat:
path: "/etc/nginx/http.d/{{ instance_name }}.conf"
get_mime: false
get_checksum: false
get_attributes: false
when: onlyifnotexist is defined and onlyifnotexist
register: cnf
- name: configure nginx for {{ instance_name }}
template:
src: nginx.conf.j2
dest: "/etc/nginx/http.d/{{ instance_name }}.conf"
mode: 0644
when: onlyifnotexist is not defined or not onlyifnotexist or not cnf.stat.exists
notify:
- reload nginx