Use realpath filter instead of the stat/dir dance

We can make the deployment more efficient if we use the realpath
filter, instead of first checking for the directory and then
implementing the changes in a follow-up task.

This is more readable, simpler and faster to execute.

Change-Id: Iaa6c1873330370ae62cd29e7d4c211c7211b703d
This commit is contained in:
Jesse Pretorius 2018-06-13 16:21:56 +01:00
parent c85793ed21
commit 311bc08503
1 changed files with 2 additions and 25 deletions

View File

@ -43,36 +43,13 @@
tags:
- haproxy-user
- name: Stat haproxy log dir
stat:
path: "/var/log/haproxy"
register: log_dir
tags:
- haproxy-dirs
- haproxy-logs
- name: Create haproxy log dir
file:
path: "/var/log/haproxy"
state: "{{ (log_dir.stat.islnk is defined and log_dir.stat.islnk) | ternary('link', 'directory') }}"
src: "{{ (log_dir.stat.islnk is defined and log_dir.stat.islnk) | ternary(log_dir.stat.lnk_source, omit) }}"
owner: haproxy
group: adm
mode: "0755"
tags:
- haproxy-dirs
- haproxy-logs
- name: Change ownership of haproxy log dir link source
file:
path: "{{ log_dir.stat.lnk_source }}"
path: "{{ '/var/log/haproxy' | realpath }}"
state: directory
owner: haproxy
group: adm
recurse: yes
when:
- log_dir.stat.islnk is defined
- log_dir.stat.islnk
mode: "0755"
tags:
- haproxy-dirs
- haproxy-logs