Skip to content

Commit fbe315c

Browse files
committed
Fix regexp match on /etc/hosts for standalone nodes
1 parent eda519e commit fbe315c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tasks/main.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@
8181
- name: Define hostname in /etc/hosts for single-host installations
8282
lineinfile:
8383
dest: /etc/hosts
84-
regexp: |-
85-
{# Match an IPv4/v6 address at the start #}
86-
^\\h*[0-9a-f:.]+
87-
{# Match at least one whitespace, and any non-hostname names #}
88-
(\\h+.*)?\\h
89-
{# Match either our fqdn or hostname #}
90-
({{ ansible_fqdn | regex_escape() }}|{{ ansible_hostname | regex_escape() }})
91-
{# Require there be a word boundary at the end of the name(s). #}
92-
{# This can be any whitespace, or end-of-line. #}
93-
(\\h+.*|\\h*)$
84+
regexp: "\
85+
{# Match an IPv4/v6 address at the start #}\
86+
^\\s*[0-9a-f:.]+\
87+
{# Match at least one whitespace, and any non-hostname names #}\
88+
(\\s+.*)*\\s\
89+
{# Match either our fqdn or hostname #}\
90+
({{ ansible_fqdn | regex_escape() }}|{{ ansible_hostname | regex_escape() }})\
91+
{# Require there be a word boundary at the end of the name(s). #}\
92+
{# This can be any whitespace, or end-of-line. #}\
93+
(\\s+.*|\\s*)$"
9494
line: "{{ hostvars[inventory_hostname].pve_cluster_addr0 }} {{ ansible_fqdn }} {{ ansible_hostname }}"
9595
backup: yes
9696
when: "not pve_cluster_enabled | bool and pve_manage_hosts_enabled | bool"

0 commit comments

Comments
 (0)