Skip to content

Commit

Permalink
fix(preinstall_config): Ensure hostname is defined in /etc/hosts file…
Browse files Browse the repository at this point in the history
… to fix 'sudo: unable to resolve host' error message
  • Loading branch information
jhampson-dbre committed Dec 27, 2020
1 parent bd8beb6 commit 695d605
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 11 additions & 0 deletions roles/preinstall_config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,22 @@ The following software is required on the control node:
Role Variables
--------------

The following facts are used by this role

```yaml
ansible_default_ipv4['address']: Use to configure static IP in /etc/hosts when `has_reserved_ip == true`
```
Variables in `defaults/main.yml` with default values

```yaml
# non-root user to create on the Home Assistant server
home_assistant_user: homeassistant
# Set this to true if you have a static IP for the Raspberry Pi
# When set to true, set the ipv4 address in /etc/hosts
# When set to false, 127.0.1.1 will be set in /etc/hosts
has_reserved_ip: false
```

Dependencies
Expand Down
3 changes: 2 additions & 1 deletion roles/preinstall_config/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
home_assistant_user: homeassistant
home_assistant_user: homeassistant
has_reserved_ip: false
10 changes: 9 additions & 1 deletion roles/preinstall_config/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@
state: present
regexp: '^%sudo'
line: '%sudo ALL=(ALL) NOPASSWD: ALL'
validate: 'visudo -cf %s'
validate: 'visudo -cf %s'

- name: Ensure hostname is in /etc/hosts
lineinfile:
path: /etc/hosts
state: present
regexp: '{{ ansible_hostname }}$'
line: "{{ has_reserved_ip | ternary(ansible_default_ipv4['address'], '127.0.1.1') }} {{ ansible_hostname }}"
validate: 'visudo -cf %s'

0 comments on commit 695d605

Please sign in to comment.