From 91bdae9611d3881924631a79b18ccce7b93dec60 Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Mon, 14 Jan 2019 14:48:49 -0800
Subject: [PATCH] Change variable naming scheme

All role variables are now prefixed with 'ntp__' instead of 'ntp_', and internal
variables are additionally prefixed with '_'. So variables meant to be used in
playbooks are named 'ntp__variable_name' and variables only meant for internal
use are named '_ntp__internal_variable_name'.
---
 README.md             | 20 ++++++++++----------
 defaults/main.yaml    | 16 ++++++++--------
 handlers/main.yaml    |  4 ++--
 tasks/main.yaml       | 32 ++++++++++++++++----------------
 templates/ntp.conf.j2 | 12 ++++++------
 vars/debian.yaml      |  2 +-
 vars/redhat.yaml      |  2 +-
 7 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/README.md b/README.md
index fad778f..d0ab189 100644
--- a/README.md
+++ b/README.md
@@ -12,20 +12,20 @@ Role Variables
 --------------
 
 If you're only trying to set up a host as a NTP client, then you can stick with
-the defaults. You may want to update the `ntp_pools` variable to point to a
+the defaults. You may want to update the `ntp__pools` variable to point to a
 closer pool, but you don't have to. Most of the other variables are only
 relevant if you're setting up a NTP server.
 
 | Variable | Default | Purpose |
 |----------|---------|---------|
-| `ntp_enabled` | `true` | Asserts whether the NTP sevice should be enabled and start at boot. |
-| `ntp_server` | `false` | Asserts whether the host should be configured to respond to time requests. |
-| `ntp_logging` | `false` | Asserts whether logging should be enabled. |
-| `ntp_sync_now` | `false` | Asserts whether the NTP service should immediately sync with its configured time servers, without regard to "easing", or errors poteentially caused by "jumps" in time. |
-| `ntp_restrict` | `['127.0.0.1', '::1']` | Additional access restrictions. We already define secure defaults based on the value of `ntp_server`. Any additional `ntp_restrict` entries are likely to allow more access. |
-| `ntp_servers` | `[]` | A list of NTP servers to query for time. **It's recommended to use `ntp_pools`**, but we support declaring specific servers too for backwards compatibility. |
-| `ntp_pools` | `[pool.ntp.org]` | A list of NTP pool addresses. Using 1 pool is fine, and will result in multiple actual servers being used. |
-| `ntp_peers` | `[]` | A list of NTP servers to peer with. You will have to add the appropriate `ntp_restrict` entries to allow peering. |
+| ntp__enabled | `true` | Asserts whether the NTP sevice should be enabled and start at boot. |
+| ntp__server | `false` | Asserts whether the host should be configured to respond to time requests. |
+| ntp__logging | `false` | Asserts whether logging should be enabled. |
+| ntp__sync_now | `false` | Asserts whether the NTP service should immediately sync with its configured time servers, without regard to "easing", or errors potentially caused by "jumps" in time. |
+| ntp__restrict | `['127.0.0.1', '::1']` | Additional access restrictions. We already define secure defaults based on the value of `ntp__server`. Any additional `ntp__restrict` entries are likely to allow more access. |
+| ntp__servers | `[]` | A list of NTP servers to query for time. **It's recommended to use `ntp__pools`**, but we support declaring specific servers too for backwards compatibility. |
+| ntp__pools | `[pool.ntp.org]` | A list of NTP pool addresses. Using 1 pool is fine, and will result in multiple actual servers being used. |
+| ntp__peers | `[]` | A list of NTP servers to peer with. You will have to add the appropriate `ntp__restrict` entries to allow peering. |
 
 Example Playbook
 ----------------
@@ -37,5 +37,5 @@ pool.
 ```
 - hosts: servers
   roles:
-    - { role: ntp, ntp_pools: [us.pool.ntp.org] }
+    - { role: ntp, ntp__pools: [us.pool.ntp.org] }
 ```
diff --git a/defaults/main.yaml b/defaults/main.yaml
index 8f5c45f..c7935db 100644
--- a/defaults/main.yaml
+++ b/defaults/main.yaml
@@ -1,18 +1,18 @@
 ---
-ntp_enabled: true
+ntp__enabled: true
 
 # Configure NTP to respond to requests for time.
-ntp_server: false
+ntp__server: false
 
 # Enable logging
-ntp_logging: false
+ntp__logging: false
 
 # Force NTP to update time immediately, without any "easing"
-ntp_sync_now: false
+ntp__sync_now: false
 
 # NTP 'restrict' directives.
 # Format: <address> [mask <mask>] [flag1] [flag2] ...
-ntp_restrict:
+ntp__restrict:
   - '127.0.0.1 # Local users have full access'
   - '::1 # Local users have full access'
 
@@ -27,12 +27,12 @@ ntp_restrict:
 # specify a public pool as a backup.
 #
 # Public NTP Pools and Servers can be found at http://www.pool.ntp.org
-ntp_servers: []
-ntp_pools:
+ntp__servers: []
+ntp__pools:
   - pool.ntp.org iburst
 
 # Peers are set up as symmetric peer servers. You will have to add the
 # appropriate 'restrict' lines above though.
-ntp_peers: []
+ntp__peers: []
 ...
 # vi: set ts=2 sts=2 sw=2 et ft=yaml: 
diff --git a/handlers/main.yaml b/handlers/main.yaml
index 99c7f97..5171e4c 100644
--- a/handlers/main.yaml
+++ b/handlers/main.yaml
@@ -1,9 +1,9 @@
 ---
 - name: restart ntp
   service:
-    name: '{{ ntp_daemon }}'
+    name: '{{ ntp__daemon }}'
     state: restarted
-  when: ntp_enabled
+  when: ntp__enabled
   become: true
 ...
 # vi: set ts=2 sts=2 sw=2 et ft=yaml: 
diff --git a/tasks/main.yaml b/tasks/main.yaml
index 845f7d5..2cb78c2 100644
--- a/tasks/main.yaml
+++ b/tasks/main.yaml
@@ -5,28 +5,28 @@
 
 - name: Check if 'timedatectl' package is installed
   command: which timedatectl
-  register: has_timedatectl
-  failed_when: has_timedatectl.rc == 2
+  register: _ntp__has_timedatectl
+  failed_when: _ntp__has_timedatectl.rc == 2
   changed_when: false
-  when: ntp_enabled
+  when: ntp__enabled
 
 - name: Check if systemd time sync is disabled
   shell: "timedatectl status | grep -c 'Network time on: no$'"
-  register: timesync_status
-  failed_when: timesync_status.rc == 2
+  register: _ntp__timesync_status
+  failed_when: _ntp__timesync_status.rc == 2
   changed_when: false
-  when: (has_timedatectl.rc is defined) and (has_timedatectl.rc == 0)
+  when: (_ntp__has_timedatectl.rc is defined) and (_ntp__has_timedatectl.rc == 0)
 
 - name: Disable systemd time sync before enabling NTP
   command: timedatectl set-ntp false
-  when: ntp_enabled and (timesync_status.rc is defined) and (timesync_status.rc == 1)
+  when: ntp__enabled and (_ntp__timesync_status.rc is defined) and (_ntp__timesync_status.rc == 1)
   become: true
 
 - name: Install the NTP package
   package:
     name: ntp
     state: present
-  register: installed
+  register: _ntp__installed
   become: true
 
 - name: Generate the NTP configuration file
@@ -36,36 +36,36 @@
     owner: root
     group: root
     mode: 0644
-  register: configured
+  register: _ntp__configured
   notify: restart ntp
   become: true
 
 - name: Stop the NTP service before forcing a time sync
   service:
-    name: '{{ ntp_daemon }}'
+    name: '{{ ntp__daemon }}'
     state: stopped
-  when: ntp_sync_now and (installed|changed or configured|changed)
+  when: ntp__sync_now and (_ntp__installed is changed or _ntp__configured is changed)
   become: true
 
 - name: Force a NTP time sync
   command: ntpd -gq
-  when: ntp_sync_now and (installed|changed or configured|changed)
+  when: ntp__sync_now and (_ntp__installed is changed or _ntp__configured is changed)
   become: true
 
 - name: Ensure NTP is running and enabled as configured
   service:
-    name: '{{ ntp_daemon }}'
+    name: '{{ ntp__daemon }}'
     state: started
     enabled: yes
-  when: ntp_enabled
+  when: ntp__enabled
   become: true
 
 - name: Ensure NTP is stopped and disabled as configured
   service:
-    name: '{{ ntp_daemon }}'
+    name: '{{ ntp__daemon }}'
     state: stopped
     enabled: no
-  when: not ntp_enabled
+  when: not ntp__enabled
   become: true
 
 ...
diff --git a/templates/ntp.conf.j2 b/templates/ntp.conf.j2
index bca9313..6472150 100644
--- a/templates/ntp.conf.j2
+++ b/templates/ntp.conf.j2
@@ -6,7 +6,7 @@
 driftfile /var/lib/ntp/ntp.drift
 
 # Enable this if you want statistics to be logged.
-{% if ntp_logging %}
+{% if ntp__logging %}
 statsdir /var/log/ntpstats/
 {% else %}
 #statsdir /var/log/ntpstats/
@@ -17,7 +17,7 @@ filegen loopstats  file loopstats  type day enable
 filegen peerstats  file peerstats  type day enable
 filegen clockstats file clockstats type day enable
 
-{% if ntp_server %}
+{% if ntp__server %}
 # By default, exchange time with everybody, but don't allow configuration
 restrict -4 default kod notrap nomodify nopeer noquery limited
 restrict -6 default kod notrap nomodify nopeer noquery limited
@@ -27,7 +27,7 @@ restrict -4 default ignore
 restrict -6 default ignore
 {% endif %}
 
-{% for restriction in ntp_restrict %}
+{% for restriction in ntp__restrict %}
 restrict {{ restriction }}
 {% endfor %}
 
@@ -36,19 +36,19 @@ restrict source notrap nomodify noquery
 
 # Add the ntp servers. You generally don't need these if you're using a pool.
 # server 0.pool.ntp.org iburst
-{% for server in ntp_servers %}
+{% for server in ntp__servers %}
 server {{ server }}
 {% endfor %}
 
 # Add the pool servers
 # pool pool.ntp.org iburst
-{% for server in ntp_pools %}
+{% for server in ntp__pools %}
 pool {{ server }}
 {% endfor %}
 
 # Add peer servers.
 # peer my.other.ntp.server
-{% for server in ntp_peers|difference(ansible_host) %}
+{% for server in ntp__peers|difference(ansible_host) %}
 peer {{ server }}
 {% endfor %}
 
diff --git a/vars/debian.yaml b/vars/debian.yaml
index 86ded05..cf8faf5 100644
--- a/vars/debian.yaml
+++ b/vars/debian.yaml
@@ -1,4 +1,4 @@
 ---
-ntp_daemon: ntp
+ntp__daemon: ntp
 ...
 # vi: set ts=2 sts=2 sw=2 et ft=yaml: 
diff --git a/vars/redhat.yaml b/vars/redhat.yaml
index 9884dfc..a1a849b 100644
--- a/vars/redhat.yaml
+++ b/vars/redhat.yaml
@@ -1,4 +1,4 @@
 ---
-ntp_daemon: ntpd
+ntp__daemon: ntpd
 ...
 # vi: set ts=2 sts=2 sw=2 et ft=yaml: 
-- 
GitLab