Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
bbaassssiiee committed Aug 30, 2022
1 parent 7e447e2 commit 4b52cbb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
6 changes: 3 additions & 3 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---

- name: Restart chronyd
service:
ansible.builtin.service:
name: "{{ nettime_service }}"
enabled: true
state: restarted

- name: Start chronyd
service:
ansible.builtin.service:
name: "{{ nettime_service }}"
state: "{{ start_nettime_service }}"

- name: Restart timedated
systemd:
ansible.builtin.systemd:
name: systemd-timedated
daemon_reload: true
enabled: true
Expand Down
6 changes: 3 additions & 3 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ galaxy_info:

license: MIT

min_ansible_version: 2.4.0
min_ansible_version: "2.9.27"

platforms:
- name: EL
versions:
- 7
- 8
- "7"
- "8"
- name: Debian
versions:
- buster
Expand Down
7 changes: 5 additions & 2 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---
- hosts: all
vars:
role_name: "{{ lookup('env','MOLECULE_PROJECT_DIRECTORY') | basename }}"
manage_firewall: false
# yamllint disable-line rule:line-length
chrony_key: '1234 SHA256 HEX:DD4E59D2CAE16FFCEBF23D67201814A2FA63251E1B23A1AF3A99203121807C6C'

roles:
- role: base_nettime
tasks:
- name: "Include {{ role_name }}"
ansible.builtin.include_role:
name: "{{ role_name }}"
...
11 changes: 6 additions & 5 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
goss_format: tap
tasks:
- name: Download and install Goss
get_url:
ansible.builtin.get_url:
url: "{{ goss_url }}"
dest: "{{ goss_dst }}"
checksum: "{{ goss_sha256sum }}"
Expand All @@ -28,26 +28,27 @@
retries: 3

- name: Register test files
shell: "ls {{ goss_test_directory }}/test_*.yml"
ansible.builtin.shell: "ls {{ goss_test_directory }}/test_*.yml"
changed_when: false
register: test_files

- name: Execute Goss tests
environment:
# yamllint disable-line rule:line-length
PATH: '/opt/rh/rh-git218/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
command: "{{ goss_dst }} -g {{ item }} validate -f {{ goss_format }}"
# yamllint disable-line rule:line-length
ansible.builtin.command: "{{ goss_dst }} -g {{ item }} validate -f {{ goss_format }}"
changed_when: false
register: test_results
with_items: "{{ test_files.stdout_lines }}"

- name: Display details about the Goss results
debug:
ansible.builtin.debug:
msg: "{{ item.stdout_lines }}"
with_items: "{{ test_results.results }}"

- name: Fail when tests fail
fail:
ansible.builtin.fail:
msg: "Goss failed to validate"
when: item.rc != 0
with_items: "{{ test_results.results }}"
Expand Down
4 changes: 2 additions & 2 deletions tasks/firewall.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---

- name: Ensure firewall is installed
package:
ansible.builtin.package:
name: "{{ nettime_firewall }}"
state: present

- name: Ensure firewall is running
systemd:
ansible.builtin.systemd:
name: "{{ nettime_firewall }}"
state: started
changed_when: false
Expand Down
28 changes: 14 additions & 14 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
- name: Include OS-specific variables.
# yamllint disable-line rule:line-length
include_vars: "{{ ansible_os_family }}{{ ansible_distribution_major_version }}.yml"
ansible.builtin.include_vars: "{{ ansible_os_family }}{{ ansible_distribution_major_version }}.yml"
tags:
- goss

- name: Update repositories cache
when: ansible_os_family == 'Debian'
apt:
ansible.builtin.apt:
update_cache: true

- name: Ensure packages are installed
package:
ansible.builtin.package:
name: "{{ nettime_packages }}"
state: present
register: nettime_package
Expand All @@ -23,13 +23,13 @@

- name: Enable systemd-timedated
when: nettime_package.failed
systemd:
ansible.builtin.systemd:
name: systemd-timedated
enabled: true
notify: "Restart timedated"

- name: Disable conflicting services
systemd:
ansible.builtin.systemd:
name: "{{ item }}"
state: stopped
enabled: false
Expand All @@ -45,7 +45,7 @@
when:
- net_allow is defined
- net_allow | length > 0
lineinfile:
ansible.builtin.lineinfile:
path: "{{ nettime_keyfile }}"
regexp: '^{{ nettime_keyid }} '
line: "{{ chrony_key }}"
Expand All @@ -61,7 +61,7 @@
notify: Restart chronyd

- name: Is RTC time in local time zone
shell: |
ansible.builtin.shell: |
set -o pipefail
timedatectl|grep -c 'RTC in local TZ: yes'
register: rtc_timezone
Expand All @@ -70,11 +70,11 @@

- name: Use RTC time in UTC not local time zone
when: rtc_timezone.stdout|int == 1
command: timedatectl set-local-rtc 0
ansible.builtin.command: timedatectl set-local-rtc 0
changed_when: true

- name: Configure chrony
template:
ansible.builtin.template:
src: chrony.conf.j2
dest: "{{ nettime_config }}"
owner: root
Expand All @@ -86,14 +86,14 @@
when:
- ansible_os_family == 'Debian'
- ansible_distribution_release == '11'
lineinfile:
ansible.builtin.lineinfile:
path: /etc/default/chrony
regexp: '^DAEMON_OPTS='
line: 'DAEMON_OPTS=""'
state: present

- name: Set drift
file:
ansible.builtin.file:
path: "{{ nettime_driftfile }}"
owner: "{{ nettime_user }}"
group: "{{ nettime_group }}"
Expand All @@ -102,21 +102,21 @@
changed_when: false

- name: Enable chronyd
systemd:
ansible.builtin.systemd:
name: "{{ nettime_service }}"
enabled: true
notify: Start chronyd

- name: Ensure goss directory exists
file:
ansible.builtin.file:
path: /etc/goss.d
state: directory
owner: root
group: root
mode: 0700

- name: Copy goss tests template
template:
ansible.builtin.template:
src: test_nettime.yml.j2
dest: /etc/goss.d/test_nettime.yml
owner: root
Expand Down

0 comments on commit 4b52cbb

Please sign in to comment.