]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding playbooks/enable-ldap-server-replication.yaml
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 29 Nov 2024 13:30:36 +0000 (14:30 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 29 Nov 2024 13:30:36 +0000 (14:30 +0100)
playbooks/enable-ldap-server-replication.yaml [new file with mode: 0644]

diff --git a/playbooks/enable-ldap-server-replication.yaml b/playbooks/enable-ldap-server-replication.yaml
new file mode 100644 (file)
index 0000000..50ee0b7
--- /dev/null
@@ -0,0 +1,71 @@
+---
+- name: "Validate the LDAP server to enable replication"
+  hosts: localhost
+  gather_facts: false
+  vars_prompt:
+    - name: ldap_server
+      prompt: "On wich LDAP server should replication be enabled"
+      private: false
+
+  tasks:
+
+    - name: "Setting fact ldapserver_to_enable."
+      ansible.builtin.set_fact:
+        ldapserver_to_enable: "{{ ldap_server }}"
+        cacheable: true
+
+    - name: "Setting status variable found_ldapserver."
+      ansible.builtin.set_fact:
+        found_ldapserver: false
+
+    - name: "Searching for LDAP server '{{ ldapserver_to_enable }}' ..."
+      ansible.builtin.set_fact:
+        found_ldapserver: true
+      when: "item == ldapserver_to_enable"
+      ignore_errors: true
+      with_inventory_hostnames:
+        - ldap_servers
+
+    - name: "Fail for non LDAP server."
+      ansible.builtin.fail:
+        msg: "The given host '{{ ldapserver_to_enable }}' is not a valid LDAP server."
+      when: found_ldapserver == false
+
+- name: "Enabling Replication on a particular LDAP server."
+  hosts: ldap_servers
+  # gather_facts: false
+
+  tasks:
+
+    - name: "Get the LDAP server to enable replication:"
+      ansible.builtin.set_fact:
+        ldapserver_to_enable: "{{ hostvars.localhost.ldapserver_to_enable }}"
+
+    - name: "The LDAP server to enable replication:"
+      debug:
+        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