Automate nordix openvpn user config files
[infra/tools.git] / infra / openvpn_automation / openvpn_user_setup.yaml
diff --git a/infra/openvpn_automation/openvpn_user_setup.yaml b/infra/openvpn_automation/openvpn_user_setup.yaml
new file mode 100644 (file)
index 0000000..3c7fe49
--- /dev/null
@@ -0,0 +1,21 @@
+---
+- name: Generate user vpn config files
+  hosts: nordix_ca
+  become: false
+  gather_facts: false
+
+  pre_tasks:
+  - name: Check user ovpn file existence
+    stat:
+      path: "{{ nordix_openvpn_clientconfig }}/files/{{ client_name }}.ovpn"
+    register: user_ovpn_file
+    delegate_to: localhost
+
+  - name: Fail the deployment
+    fail:
+      msg:
+        - "{{ client_name }}.ovpn file already exist under '{{ nordix_openvpn_clientconfig }}/files/{{ client_name }}.ovpn' or Client name is not defined"
+    when: client_name is not defined and client_name | length > 0 or user_ovpn_file.stat.exists
+
+  roles:
+    - {role: generate-user-ovpn, when: client_name is defined and client_name | length > 0}