Don't assume /etc/hosts exists

The baremetal role adds entries to /etc/hosts. If the file does not
exist, it will fail:

  TASK [baremetal : Ensure localhost in /etc/hosts] ****************************************
  fatal: [compute2]: FAILED! => {"changed": false, "msg": "Destination /etc/hosts does not exist !", "rc": 257}

Though surprising, this is possible, and we should not assume that
/etc/hosts exists.

This change modifies the above task to create the file if it does not
exist.

Closes-Bug: #1982837
Change-Id: Ic419ee13a10b3fa1b890cfec23bab0a67489eb96
This commit is contained in:
Mark Goddard 2022-07-26 13:58:38 +01:00
parent 1fb0e56697
commit 25020e469f

View File

@ -4,6 +4,8 @@
dest: /etc/hosts
regexp: "^127.0.0.1.*"
line: "127.0.0.1 localhost"
create: true
mode: 0644
state: present
become: True
when: customize_etc_hosts | bool