Skip to content
Snippets Groups Projects
Commit 080aaeed authored by nimrod's avatar nimrod
Browse files

- Start work on role (just installation, mail alias, service handling,

minimal tests)
- Better assertions.
parent 0f5071de
No related branches found
No related tags found
No related merge requests found
--- ---
# defaults file for dhcp # defaults file for dhcp
dhcp_mail_alias: root
--- ---
# handlers file for dhcp # handlers file for dhcp
- name: Update SMTPd database
when: ansible_os_family == 'OpenBSD'
command: /usr/bin/newaliases
- name: Restart ISC DHCP server
service:
name: '{{ dhcp_service[ansible_os_family] }}'
state: restarted
...@@ -4,5 +4,35 @@ ...@@ -4,5 +4,35 @@
- name: Assertions - name: Assertions
assert: assert:
that: that:
- ansible_os_family in ['OpenBSD', 'Debian'] - ansible_os_family in dhcp_service
- ansible_distribution_release in ['6.0', 'xenial'] - ansible_os_family in dhcp_user
- ansible_os_family in aliases_file
- name: APT install
apt:
name: isc-dhcp-server
state: present
update_cache: yes
cache_valid_time: 3600
- name: Add mail alias
when: dhcp_mail_alias is defined
lineinfile:
dest: '{{ aliases_file[ansible_os_family] }}'
create: yes
line: '{{ dhcp_user[ansible_os_family] }}: {{ dhcp_mail_alias }}'
regexp: '{{ dhcp_user[ansible_os_family] }}:'
notify:
- Update SMTPd database
- name: Enable service
service:
name: '{{ dhcp_service[ansible_os_family] }}'
state: running
enabled: yes
- meta: flush_handlers
- name: Wait for service to come online
wait_for:
port: 67
from testinfra.utils.ansible_runner import AnsibleRunner
testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')
def test_dhcp_service(Service, Socket, SystemInfo):
if SystemInfo.type == 'openbsd':
service = Service('dhcpd')
elif SystemInfo.type == 'debian':
service = Service('isc-dhcp-server')
assert service.is_running
try:
assert service.is_enabled
except NotImplementedError:
pass
assert Socket('tcp://0.0.0.0:80').is_listening
--- ---
# vars file for dhcp # vars file for dhcp
dhcp_service:
OpenBSD: dhcpd
Debian: isc-dhcp-server
aliases_file:
OpenBSD: /etc/mail/aliases
Debian: /etc/aliases
dhcp_user:
OpenBSD: _dhcp
Debian: dhcp
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment