Skip to content

Commit

Permalink
Version 2.1.0
Browse files Browse the repository at this point in the history
add exlude feature
  • Loading branch information
sbaerlocher authored Dec 5, 2020
2 parents 44f7462 + ff606dc commit 362cb12
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 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/).

## 2.1.0

### Added

- Added an option to exclude interfases.

## 2.0.0

### Added
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- markdownlint-disable MD013 -->

[![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square&logo=Open%20Source%20Initiative)](LICENSE) [![Ansible Role](https://img.shields.io/ansible/role/24841?label=role%20name&style=flat-square&logo=ansible)](https://galaxy.ansible.com/arillso/hosts) [![Ansible Role](https://img.shields.io/ansible/role/d/24841.svg?style=flat-square&logo=ansible)](https://galaxy.ansible.com/arillso/hosts) [![Ansible Quality Score](https://img.shields.io/ansible/quality/24841?label=role%20quality&style=flat-square&logo=ansible)](https://galaxy.ansible.com/arillso/hosts) [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/arillso/ansible.hosts?style=flat-square&logo=github)](https://github.com/arillso/ansible.hosts/releases) [![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/arillso/ansible.hosts/Role%20Tests/master?label=integration%20tests&style=flat-square&logo=github)](https://github.com/arillso/ansible.hosts/actions?query=workflow%3A%22Role+Tests%22)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square&logo=Open%20Source%20Initiative)](LICENSE) [![Ansible Role](https://img.shields.io/ansible/role/24841?label=role%20name&style=flat-square&logo=ansible)](https://galaxy.ansible.com/arillso/hosts) [![Ansible Role](https://img.shields.io/ansible/role/d/24841.svg?style=flat-square&logo=ansible)](https://galaxy.ansible.com/arillso/hosts) [![Ansible Quality Score](https://img.shields.io/ansible/quality/24841?label=role%20quality&style=flat-square&logo=ansible)](https://galaxy.ansible.com/arillso/hosts) [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/arillso/ansible.hosts?style=flat-square&logo=github)](https://github.com/arillso/ansible.hosts/releases) [![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/arillso/ansible.hosts/Role%20Tests/main?label=tests&style=flat-square&logo=github)](https://github.com/arillso/ansible.hosts/actions?query=workflow%3A%22Role+Tests%22)

<!-- markdownlint-enable MD012 -->

Expand Down Expand Up @@ -123,6 +123,16 @@ Address that you would like to use as IPv4 address. This could be overriden by w
hosts_ipv4_address: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
```

### hosts_exludes_interfaces

List of network cards that should not be added to the hosts file.

```yml
hosts_exludes_interfaces:
- 'vet*'
- 'docker'
```

## Dependencies

None
Expand Down
5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ hosts_ipv6: true

# Set ipv4 address (could be override by what you want)
hosts_ipv4_address: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"

# List of network cards that should not be added to the hosts file.
hosts_exludes_interfaces:
- 'vet*'
- 'docker'
4 changes: 2 additions & 2 deletions templates/etc/hosts.j2
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ff02::3 ip6-allhosts
{% for host in groups['all'] %}
{% if hostvars[host]['ansible_interfaces'] is defined %}
{% for interface in hostvars[host]['ansible_interfaces'] %}
{% if "br" not in interface %}
{% if interface | regex_search('^((?!' + hosts_exludes_interfaces | join('|') + '*).)*$') %}
{% if hostvars[host]['ansible_' + interface]['ipv4']['address'] | ansible.netcommon.ipaddr('private') and hosts_all_private %}
{{ hostvars[host]['ansible_' + interface]['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }}{{ " " if hostvars[host]['hosts_aliases'] is defined }}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{{ alias }}{{ " " if not loop.last }}{% endfor %}{% endif %}{{ '\n' -}}
{% elif hostvars[host]['ansible_' + interface]['ipv4']['address'] | ansible.netcommon.ipaddr('public') and hosts_all_public %}
Expand All @@ -47,7 +47,7 @@ ff02::3 ip6-allhosts
{% for host in groups['all'] %}
{% if hostvars[host]['ansible_interfaces'] is defined %}
{% for interface in hostvars[host]['ansible_interfaces'] %}
{% if "br" not in interface %}
{% if interface | regex_search('^((?!' + hosts_exludes_interfaces | join('|') + '*).)*$') %}
{% if hostvars[host]['ansible_' + interface]['ipv6']['address'] | ansible.netcommon.ipaddr('private') and hosts_all_private %}
{{ hostvars[host]['ansible_' + interface]['ipv6']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }} {% set aliases=[] %}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{% if alias != hostvars[host]['internel_ansible_host'] %}{{ aliases.append(alias) }}{% endif %}{% endfor %}{% endif %}
{% elif hostvars[host]['ansible_' + interface]['ipv6']['address'] | ansible.netcommon.ipaddr('public') and hosts_all_public %}
Expand Down

0 comments on commit 362cb12

Please sign in to comment.