From 8f89db1f4cbf3d9b48da5fa048eacc9ce3e8bcf2 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 4 Dec 2024 16:52:20 +0100 Subject: [PATCH] Adding and using Ansible role set-timestamp-vars --- playbooks/disable-ldap-server.yaml | 26 +++-------------- playbooks/enable-ldap-server-replication.yaml | 25 +++-------------- roles/set-timestamp-vars/tasks/main.yaml | 28 +++++++++++++++++++ 3 files changed, 36 insertions(+), 43 deletions(-) create mode 100644 roles/set-timestamp-vars/tasks/main.yaml diff --git a/playbooks/disable-ldap-server.yaml b/playbooks/disable-ldap-server.yaml index 65b8d85..41b36b4 100644 --- a/playbooks/disable-ldap-server.yaml +++ b/playbooks/disable-ldap-server.yaml @@ -74,6 +74,10 @@ tasks: + - name: "Setting timestamp variables." + include_role: + name: set-timestamp-vars + - name: "Get the LDAP server to disable replication:" ansible.builtin.set_fact: ldapserver_to_disable: "{{ hostvars.localhost.ldapserver_to_disable }}" @@ -84,28 +88,6 @@ var: ldapserver_to_disable verbosity: 0 - - name: Get timestamp from the system - ansible.builtin.shell: date +%Y-%m-%d_%H-%M-%S - register: tstamp - check_mode: false - changed_when: false - - - name: "Show current timestamp" - debug: - var: tstamp - verbosity: 3 - - - name: "Set date variables" - set_fact: - cur_date: "{{ tstamp.stdout[0:10] | default('2024-11-11') }}" - cur_time: "{{ tstamp.stdout[11:] | default('16-33-23') }}" - cur_timestamp: "{{ tstamp.stdout[0:10] }}_{{ tstamp.stdout[11:] | default('2024-11-11_16-33-23') }}" - - - name: "Show current date" - debug: - msg: "Current timestamp: '{{ cur_timestamp }}'." - verbosity: 0 - - name: "Initial set target_replica_id" ansible.builtin.set_fact: target_replica_id: ~ diff --git a/playbooks/enable-ldap-server-replication.yaml b/playbooks/enable-ldap-server-replication.yaml index 7ab29a5..289c664 100644 --- a/playbooks/enable-ldap-server-replication.yaml +++ b/playbooks/enable-ldap-server-replication.yaml @@ -41,6 +41,10 @@ include_role: name: 389ds-check-initial + - name: "Setting timestamp variables." + include_role: + name: set-timestamp-vars + - name: "Get the LDAP server to enable replication:" ansible.builtin.set_fact: ldapserver_to_enable: "{{ hostvars.localhost.ldapserver_to_enable }}" @@ -50,26 +54,5 @@ var: ldapserver_to_enable verbosity: 0 - - name: "Get timestamp from the system" - ansible.builtin.shell: date +%Y-%m-%d_%H-%M-%S - register: tstamp - check_mode: false - changed_when: false - - - name: "Show current timestamp" - debug: - var: tstamp - verbosity: 3 - - - name: "Set date variables" - set_fact: - cur_date: "{{ tstamp.stdout[0:10] | default('2024-11-11') }}" - cur_time: "{{ tstamp.stdout[11:] | default('16-33-23') }}" - cur_timestamp: "{{ tstamp.stdout[0:10] }}_{{ tstamp.stdout[11:] | default('2024-11-11_16-33-23') }}" - - - name: "Show current date" - debug: - msg: "Current timestamp: '{{ cur_timestamp }}'." - verbosity: 0 # vim: filetype=yaml diff --git a/roles/set-timestamp-vars/tasks/main.yaml b/roles/set-timestamp-vars/tasks/main.yaml new file mode 100644 index 0000000..4d983b7 --- /dev/null +++ b/roles/set-timestamp-vars/tasks/main.yaml @@ -0,0 +1,28 @@ +--- + +# Setting timestamp variables on base of the local time on the apropiate hosts + +- name: "Get timestamp from the system" + ansible.builtin.shell: date +%Y-%m-%d_%H-%M-%S%:z + register: get_tstamp + check_mode: false + changed_when: false + +- name: "Show current timestamp" + debug: + var: get_tstamp + verbosity: 3 + +- name: "Set date variables" + set_fact: + cur_date: "{{ get_tstamp.stdout[0:10] }}" + cur_time: "{{ get_tstamp.stdout[11:19] }}" + cur_timestamp: "{{ get_tstamp.stdout[0:10] }}_{{ get_tstamp.stdout[11:19] }}" + cur_timezone: "{{ get_tstamp.stdout[19:] }}" + +- name: "Show current timestamp" + debug: + msg: "cur_timestamp: '{{ cur_timestamp }} {{ cur_timezone }}'" + verbosity: 0 + +# vim: filetype=yaml -- 2.39.5