Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a list of additional hosts to /etc/hosts #447

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/etc_hosts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- "orahost: Add a list of additional hosts to /etc/hosts (oravirt#447)"
26 changes: 26 additions & 0 deletions roles/orahost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Role to configure the hostsystem for ansible-oracle
- [disable_firewall](#disable_firewall)
- [disable_numa_boot](#disable_numa_boot)
- [disable_selinux](#disable_selinux)
- [etc_hosts_entries](#etc_hosts_entries)
- [etc_hosts_ip](#etc_hosts_ip)
- [extrarepos_disabled](#extrarepos_disabled)
- [extrarepos_enabled](#extrarepos_enabled)
Expand Down Expand Up @@ -284,6 +285,31 @@ disable_numa_boot: true
disable_selinux: true
```

### etc_hosts_entries

List of additional entries, optionally along with aliases, to be put into /etc/hosts. E.g. on non-DNS environments or if we don't rely on DNS

#### Default value

```YAML
etc_hosts_entries: []
```

#### Example usage

```YAML
etc_hosts_entries:
- fqdn: clusternode1.example.com
ip: 192.168.1.1
- fqdn: clusternode2.example.com
ip: 192.168.1.2
aliases:
- myalias.example.com
would create following entries in /etc/hosts:
192.168.1.1 clusternode1 clusternode1.example.com
192.168.1.2 clusternode2 clusternode2.example.com myalias.example.com
```

### etc_hosts_ip

Set IP to 2nd Interface on virtualbox and 1st for all otehr installations
Expand Down
17 changes: 17 additions & 0 deletions roles/orahost/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ sudoers_template: sudoers.j2
# @end
etc_hosts_ip: "{% if 'virtualbox' in ansible_virtualization_type %}{{ ansible_all_ipv4_addresses[1] }}{% else %}{{ ansible_default_ipv4.address }}{% endif %}"

# @var etc_hosts_entries:description: >
# List of additional entries, optionally along with aliases, to be put into /etc/hosts. E.g. on non-DNS environments or if we don't rely on DNS
# @end
# @var etc_hosts_entries:example: >
# etc_hosts_entries:
# - fqdn: clusternode1.example.com
# ip: 192.168.1.1
# - fqdn: clusternode2.example.com
# ip: 192.168.1.2
# aliases:
# - myalias.example.com
# would create following entries in /etc/hosts:
# 192.168.1.1 clusternode1 clusternode1.example.com
# 192.168.1.2 clusternode2 clusternode2.example.com myalias.example.com
# @end
etc_hosts_entries: []

# Extra repositories that should be enabled
extrarepos_enabled: "{%- if ansible_distribution == 'OracleLinux' -%}\
ol{{ ansible_distribution_major_version }}_addons\
Expand Down
19 changes: 19 additions & 0 deletions roles/orahost/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@
when: configure_etc_hosts
tags: etchosts

- name: Add manually defined hosts to /etc/hosts
# e.g. on non-DNS environments or if we don't rely on DNS
ansible.builtin.lineinfile:
dest: /etc/hosts

Check warning on line 51 in roles/orahost/tasks/main.yml

View workflow job for this annotation

GitHub Actions / build

jinja[spacing]

Jinja2 spacing could be improved: {{ __orahost_etc_hosts_entry.ip }} {{ (__orahost_etc_hosts_entry.fqdn|split('.'))[0] }} {{ __orahost_etc_hosts_entry.fqdn is search('\.') | ternary(__orahost_etc_hosts_entry.fqdn, '') }}{% for alias in __orahost_etc_hosts_entry.aliases|default([]) %} {{ alias }}{% endfor %} # ANSIBLE managed -> {{ __orahost_etc_hosts_entry.ip }} {{ (__orahost_etc_hosts_entry.fqdn | split('.'))[0] }} {{ __orahost_etc_hosts_entry.fqdn is search('\.') | ternary(__orahost_etc_hosts_entry.fqdn, '') }}{% for alias in __orahost_etc_hosts_entry.aliases | default([]) %} {{ alias }}{% endfor %} # ANSIBLE managed
regexp: '.*{{ __orahost_etc_hosts_entry.fqdn }}$'
line:
"{{ __orahost_etc_hosts_entry.ip }}
{{ (__orahost_etc_hosts_entry.fqdn|split('.'))[0] }}
{{ __orahost_etc_hosts_entry.fqdn is search('\\.') | ternary(__orahost_etc_hosts_entry.fqdn, '') }}\
{% for alias in __orahost_etc_hosts_entry.aliases|default([]) %} {{ alias }}{% endfor %} # ANSIBLE managed"
state: present
loop: "{{ etc_hosts_entries }}"
loop_control:
loop_var: __orahost_etc_hosts_entry
when:
- configure_etc_hosts
- etc_hosts_entries|type_debug == "list"
tags: etchosts

# - name: Add local node's ip & hostname to /etc/hosts
# lineinfile: dest=/etc/hosts line="{{ ansible_default_ipv4.address }} {{ ansible_fqdn }} {{ ansible_hostname }} " state=present
# when: configure_etc_hosts and ansible_default_ipv4.address is defined
Expand Down
Loading