Skip to content

Commit

Permalink
tasks: use list of parameters for ansible conditions since those are …
Browse files Browse the repository at this point in the history
…internally identical to using logical 'and' operator
  • Loading branch information
paulfantom committed May 10, 2019
1 parent 5ab0443 commit 578706a
Showing 1 changed file with 44 additions and 14 deletions.
58 changes: 44 additions & 14 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
- name: Check if single PTP is needed
set_fact:
timesync_mode: 2
when: timesync_mode is not defined and (timesync_ntp_servers|length == 0) and timesync_ptp_domains|length == 1 and timesync_ptp_domains[0].interfaces|length == 1
when:
- timesync_mode is not defined
- timesync_ntp_servers|length == 0
- timesync_ptp_domains|length == 1
- timesync_ptp_domains[0].interfaces|length == 1

- name: Check if both NTP and PTP are needed
set_fact:
Expand All @@ -17,20 +21,28 @@

- name: Determine current NTP provider
timesync_provider:
when: timesync_mode != 2 and (timesync_ntp_provider is not defined or timesync_ntp_provider == '')
when:
- timesync_mode != 2
- (timesync_ntp_provider is not defined or timesync_ntp_provider == '')

- name: Select NTP provider
set_fact:
timesync_ntp_provider: "{{ timesync_ntp_provider_os_default if timesync_ntp_provider_current == '' else timesync_ntp_provider_current }}"
when: timesync_mode != 2 and (timesync_ntp_provider is not defined or timesync_ntp_provider == '')
when:
- timesync_mode != 2
- (timesync_ntp_provider is not defined or timesync_ntp_provider == '')

- name: Install chrony
package: name=chrony state=present
when: timesync_mode != 2 and timesync_ntp_provider == 'chrony'
when:
- timesync_mode != 2
- timesync_ntp_provider == 'chrony'

- name: Install ntp
package: name=ntp state=present
when: timesync_mode != 2 and timesync_ntp_provider == 'ntp'
when:
- timesync_mode != 2
- timesync_ntp_provider == 'ntp'

- name: Install linuxptp
package: name=linuxptp state=present
Expand Down Expand Up @@ -62,27 +74,37 @@
warn: no
register: timesync_ntp_version
changed_when: False
when: timesync_mode != 2 and timesync_ntp_provider == 'ntp'
when:
- timesync_mode != 2
- timesync_ntp_provider == 'ntp'

- name: Generate chrony.conf file
template: src=chrony.conf.j2 dest=/etc/chrony.conf backup=yes mode=0644
notify: restart {{ 'chronyd' if timesync_mode == 1 else 'timemaster' }}
when: timesync_mode != 2 and timesync_ntp_provider == 'chrony'
when:
- timesync_mode != 2
- timesync_ntp_provider == 'chrony'

- name: Generate chronyd sysconfig file
template: src=chronyd.sysconfig.j2 dest=/etc/sysconfig/chronyd backup=yes mode=0644
notify: restart chronyd
when: timesync_mode == 1 and timesync_ntp_provider == 'chrony'
when:
- timesync_mode == 1
- timesync_ntp_provider == 'chrony'

- name: Generate ntp.conf file
template: src=ntp.conf.j2 dest=/etc/ntp.conf backup=yes mode=0644
notify: restart {{ 'ntpd' if timesync_mode == 1 else 'timemaster' }}
when: timesync_mode != 2 and timesync_ntp_provider == 'ntp'
when:
- timesync_mode != 2
- timesync_ntp_provider == 'ntp'

- name: Generate ntpd sysconfig file
template: src=ntpd.sysconfig.j2 dest=/etc/sysconfig/ntpd backup=yes mode=0644
notify: restart ntpd
when: timesync_mode == 1 and timesync_ntp_provider == 'ntp'
when:
- timesync_mode == 1
- timesync_ntp_provider == 'ntp'

- name: Generate ptp4l.conf file
template: src=ptp4l.conf.j2 dest=/etc/ptp4l.conf backup=yes mode=0644
Expand All @@ -97,7 +119,9 @@
- name: Generate phc2sys sysconfig file
template: src=phc2sys.sysconfig.j2 dest=/etc/sysconfig/phc2sys backup=yes mode=0644
notify: restart phc2sys
when: timesync_mode == 2 and timesync_mode2_hwts
when:
- timesync_mode == 2
- timesync_mode2_hwts

- name: Generate timemaster.conf file
template: src=timemaster.conf.j2 dest=/etc/timemaster.conf backup=yes mode=0644
Expand Down Expand Up @@ -151,19 +175,25 @@

- name: Enable chronyd
service: name=chronyd state=started enabled=yes
when: timesync_mode == 1 and timesync_ntp_provider == 'chrony'
when:
- timesync_mode == 1
- timesync_ntp_provider == 'chrony'

- name: Enable ntpd
service: name=ntpd state=started enabled=yes
when: timesync_mode == 1 and timesync_ntp_provider == 'ntp'
when:
- timesync_mode == 1
- timesync_ntp_provider == 'ntp'

- name: Enable ptp4l
service: name=ptp4l state=started enabled=yes
when: timesync_mode == 2

- name: Enable phc2sys
service: name=phc2sys state=started enabled=yes
when: timesync_mode == 2 and timesync_mode2_hwts
when:
- timesync_mode == 2
- timesync_mode2_hwts

- name: Enable timemaster
service: name=timemaster state=started enabled=yes
Expand Down

0 comments on commit 578706a

Please sign in to comment.