Skip to content

Commit

Permalink
Merge pull request #17 from smutel/AddInventoryOption
Browse files Browse the repository at this point in the history
Add an option to use inventory IP
  • Loading branch information
sbaerlocher authored Oct 8, 2020
2 parents bcb928a + 47247a6 commit 2810539
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
and [human-readable changelog](https://keepachangelog.com/en/1.0.0/).

## 1.8.0

### Added

- Add an option to use inventory IP

## 1.7.3

### Fixed
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ hosts_seuser: system_u
hosts_selevel: s0
```
### Loppback
### Loopback
Creates a 127.0.0.1 entry for the server name.
Expand All @@ -88,6 +88,14 @@ Ipv6 localhost entries are set automatically. Setting false it can be prevented.
hosts_ipv6: true
```

### IPv4 address

Address that you would like to use as IPv4 address. This could be overriden by what you want.

```yml
hosts_ipv4_address: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
```

## Dependencies

None
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ hosts_inventory_to_hosts: false
# Ipv6 localhost entries are set automatically.
# Setting false it can be prevented.
hosts_ipv6: true

# Set ipv4 address (could be override by what you want)
hosts_ipv4_address: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
2 changes: 1 addition & 1 deletion templates/etc/hosts.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% endif %}
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }} {{ inventory_hostname | lower }} {{ inventory_hostname_short | lower }}
{{ hosts_ipv4_address }} {{ inventory_hostname | lower }} {{ inventory_hostname_short | lower }}
{% if ansible_lo.ipv6 is defined and hosts_ipv6 %}

# The following lines are desirable for IPv6 capable hosts
Expand Down

0 comments on commit 2810539

Please sign in to comment.