Skip to content

Commit

Permalink
fix: add hostname_custom_name, tags, change docs, add gitlab-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Mar 7, 2017
1 parent a0e4202 commit b9234b3
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
test:
tags:
- vagrant
script:
- molecule --debug test
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
---
language: python
python: "2.7"
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq python-apt python-pycurl
install:
- pip install ansible==1.5.0
install: pip install ansible
script:
- echo localhost > inventory
- ansible-playbook -i inventory test.yml --syntax-check
Expand All @@ -15,3 +11,6 @@ script:
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## ANXS - hostname [![Build Status](https://travis-ci.org/ANXS/hostname.png)](https://travis-ci.org/ANXS/hostname)
## ANXS - hostname [![Build Status](https://travis-ci.org/viasite-ansible/hostname.png)](https://travis-ci.org/viasite-ansible/hostname)

Ansible role that sets the hostname and FQDN of the node.

Expand All @@ -11,10 +11,6 @@ Add the hosts to your inventory with their FQDN (e.g. foo.bar.com), and the role

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 and libnss-mdns. This is useful in vagrant.
```
#### Example

Your inventory file should look like this:
Expand All @@ -37,13 +33,3 @@ And the structure of the files in your host_vars folders should match accordingl
This project comes with a VagrantFile, this is a fast and easy way to test changes to the role, fire it up with `vagrant up`

See [vagrant docs](https://docs.vagrantup.com/v2/) for getting setup with vagrant


#### License

Licensed under the MIT License. See the LICENSE file for details.


#### Feedback, bug-reports, requests, ...

Are [welcome](https://github.com/ANXS/hostname/issues)!
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# file: hostname/defaults/main.yml

hostname_avahi: no
hostname_custom_name: "{{inventory_hostname_short}}"
12 changes: 5 additions & 7 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# file: hostname/meta/main.yml

galaxy_info:
author: pjan vandaele
company: ANXS
author: Stanislav Popov
company: Viasite
description: sets the hostname and FQDN
min_ansible_version: 1.3
min_ansible_version: 1.8
license: MIT
platforms:
- name: Ubuntu
versions:
- all
categories:
- system
- system

dependencies:
- role: ANXS.apt
when: hostname_avahi|lower == "true"
dependencies: []
33 changes: 33 additions & 0 deletions molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
dependency:
name: galaxy

# cannot test with docker
driver:
name: vagrant
vagrant:
platforms:
- name: xenial64
box: bento/ubuntu-16.04
ansible_groups:
- group1
providers:
- name: virtualbox
type: virtualbox
options:
memory: 512
cpus: 2
instances:
- name: vagrant-01
ansible_groups:
- group_1
interfaces:
- network_name: private_network
type: dhcp
auto_config: true

ansible:
playbook: tests/playbook.yml
group_vars:
all:
hostname_custom_name: test.example.com
16 changes: 8 additions & 8 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

- name: Hostname | Update the hostname (pt. 1) - hostname cmd
hostname:
name: "{{inventory_hostname_short}}"
name: "{{hostname_custom_name}}"
tags: hostname

- name: Hostname | Update the hostname (pt. 2) - (/etc/hostname)
copy:
content: "{{inventory_hostname_short}}{{'\n'}}"
content: "{{hostname_custom_name}}{{'\n'}}"
dest: /etc/hostname
owner: root
group: root
mode: 0644
tags: hostname

- name: Hostname | Update the IPv4 hostname (pt. 3) - (/etc/hosts)
lineinfile:
dest: /etc/hosts
regexp: "^127.0.0.1"
line: "127.0.0.1{{'\t'}}{{inventory_hostname}}{% if inventory_hostname != inventory_hostname_short %}{{'\t'}}{{inventory_hostname_short}}{% endif %}{{'\t'}}localhost"
line: "127.0.0.1{{'\t'}}{{inventory_hostname}}{% if inventory_hostname != hostname_custom_name %}{{'\t'}}{{hostname_custom_name}}{% endif %}{{'\t'}}localhost"
state: present
tags: hostname

- name: Hostname | Update the IPv6 hostname (pt. 3) - (/etc/hosts)
lineinfile:
dest: /etc/hosts
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"
line: "::1{{'\t\t'}}{{inventory_hostname}}{% if inventory_hostname != hostname_custom_name %}{{'\t'}}{{hostname_custom_name}}{% endif %}{{'\t'}}localhost ip6-localhost ip6-loopback"
state: present

- name: Hostname | Install MDNS Components
apt: pkg=avahi-daemon,libnss-mdns state=latest
when: "'{{ansible_os_family}}' == 'Debian' and {{hostname_avahi}}"
tags: hostname
4 changes: 4 additions & 0 deletions tests/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- hosts: all
roles:
- ""

0 comments on commit b9234b3

Please sign in to comment.