initial commit

This commit is contained in:
Robert Kaussow 2017-05-18 23:10:07 +02:00
parent 92ea85606a
commit 35414f0fed
7 changed files with 92 additions and 0 deletions

4
defaults/main.yml Normal file
View File

@ -0,0 +1,4 @@
---
def_network:
disable_ipv6: false
network: {}

30
handlers/main.yml Normal file
View File

@ -0,0 +1,30 @@
---
- name: restart network
shell: sleep 2 && systemctl restart network
async: 1
poll: 0
ignore_errors: true
when: not require_reboot
listen:
- "network_restart"
- name: reboot server
shell: sleep 2 && shutdown -r now "Reboot triggered by Ansible"
async: 1
poll: 0
ignore_errors: true
when: require_reboot
listen:
- "host_reboot"
- name: wait for host
local_action:
module: wait_for
host={{ network.config[network.defaultif].ipaddr }}
port=22
delay=1
timeout=300
listen:
- "network_restart"
- "host_reboot"

35
tasks/config.yml Normal file
View File

@ -0,0 +1,35 @@
---
- name: set hostname
template:
src: 'etc/hostname.j2'
dest: '/etc/hostname'
owner: root
group: root
mode: 0644
register: hostname_result
notify:
- host_reboot
- name: set hosts file
template:
src: 'etc/hosts.j2'
dest: '/etc/hosts'
owner: root
group: root
mode: 0644
register: hosts_result
notify:
- host_reboot
- name: interface configuration
template:
src: 'etc/sysconfig/network-scrips/ifcfg.j2'
dest: '/etc/sysconfig/network-scripts/ifcfg-{{ item.key }}'
owner: root
group: root
mode: 0644
with_dict: '{{ network.config }}'
when: item.key in ansible_interfaces
notify:
- network_restart

5
tasks/main.yml Normal file
View File

@ -0,0 +1,5 @@
---
- name: custom fact
set_fact:
require_reboot: "{{ true if network.fqdn != ansible_fqdn else false }}"
- include: config.yml

View File

@ -0,0 +1,3 @@
{% if network.hostname is defined %}
{{ network.hostname }}
{% endif %}

9
templates/etc/hosts.j2 Normal file
View File

@ -0,0 +1,9 @@
#jinja2: trim_blocks: True, lstrip_blocks: True
# {{ ansible_managed }}
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
{% if network.disable_ipv6 == false %}
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
{% endif %}
{% if network.hostname is defined and network.fqdn is defined and network.config[network.defaultif].ipaddr is defined %}
{{ network.config[network.defaultif].ipaddr }} {{ network.fqdn }} {{ network.hostname }}
{% endif %}

View File

@ -0,0 +1,6 @@
#jinja2: trim_blocks: True, lstrip_blocks: True
# {{ ansible_managed }}
DEVICE="{{ item.key }}"
{%+ for key, value in item.value.items() -%}
{{ key|upper }}="{{ value }}"
{% endfor %}