Skip to content

Commit

Permalink
Merge pull request ANXS#8 from ANXS/jfreedman/avahi
Browse files Browse the repository at this point in the history
optionally install avahi for mdns support (useful in vagrant)
  • Loading branch information
David Farrington committed Mar 28, 2015
2 parents 56b48ff + 3d6fe6d commit fdc4228
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ Ansible role that sets the hostname and FQDN of the node.

#### Variables

This role fully depends on your ansible hosts inventory.
This depends on your ansible hosts inventory.

Add the hosts to your inventory with their FQDN (e.g. foo.bar.com), and the role will take care of setting your hostname accordingly (hostname: foo, FQDN: foo.bar.com).

If you just name it with the hostname in the inventory, it will similarly work (hostname set, but no FQDN attached to it).

```yaml
hostname_avahi: no # You may optionall install avahi-mdns. This is useful in vagrant.
```
#### Example
Expand Down
4 changes: 4 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

hostname_avahi = ENV.key?('HOSTNAME_AVAHI') ? ENV['HOSTNAME_AVAHI'] : 'false'
Vagrant.configure('2') do |config|
config.vm.define 'anxs' do |c|
c.vm.box = 'ubuntu/trusty64'
Expand All @@ -11,6 +12,9 @@ Vagrant.configure('2') do |config|
ansible.sudo = true
ansible.inventory_path = 'vagrant-inventory'
ansible.host_key_checking = false
ansible.extra_vars = {
hostname_avahi: hostname_avahi
}
end
end
end
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# file: hostname/defaults/main.yml

hostname_avahi: no
4 changes: 3 additions & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ galaxy_info:
categories:
- system

dependencies: []
dependencies:
- role: ANXS.apt
when: hostname_avahi|lower == "true"
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
regexp: "^::1"
line: "::1{{'\t\t'}}{{inventory_hostname}}{% if inventory_hostname != inventory_hostname_short %}{{'\t'}}{{inventory_hostname_short}}{% endif %}{{'\t'}}localhost ip6-localhost ip6-loopback"
state: present

- name: Hostname | Install Avahi-MDNS
apt: pkg=avahi-daemon state=latest
when: "'{{ansible_os_family}}' == 'Debian' and {{hostname_avahi}}"
2 changes: 2 additions & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- hosts: all
vars_files:
- 'defaults/main.yml'
tasks:
- include: 'tasks/main.yml'

0 comments on commit fdc4228

Please sign in to comment.