From 2afd0b52d08078b40c1f78f55cf97262478aae2c Mon Sep 17 00:00:00 2001
From: Niculut Laurentiu <Laurentiu.Niculut2@hpecds.com>
Date: Tue, 14 Dec 2021 09:03:32 +0100
Subject: [PATCH] added output examples

---
 Databases-templates/mysql-play.tpl           | 65 ++++++++++++++++----
 Docker-services-templates/wordpress-play.tpl | 39 +++++++++++-
 ansibleUtils.py                              |  2 +-
 3 files changed, 91 insertions(+), 15 deletions(-)

diff --git a/Databases-templates/mysql-play.tpl b/Databases-templates/mysql-play.tpl
index 8ffca58..fcbfa71 100644
--- a/Databases-templates/mysql-play.tpl
+++ b/Databases-templates/mysql-play.tpl
@@ -10,13 +10,38 @@
     with_items:
     - mysql-server
     - mysql-client
-    - python-mysqldb
     - python-setuptools
-    - python-pip
+    - python-mysqldb
     - libmysqlclient-dev
+    - python3-pip
+
+  - name: Remove a symbolic link
+    ansible.builtin.file: 
+      path: /usr/bin/python
+      state: absent
+
+  - name: Create a symbolic link
+    ansible.builtin.file: 
+      src: /usr/bin/python3
+      dest: /usr/bin/python
+      state: link
+    register: result
+    retries: 3
+    delay: 5
+    until: result is not failed
 
-  - name: "Install Python packages"
-    pip: "name={{ item }}  state=present"
+  - name: Create a symbolic link
+    ansible.builtin.file: 
+      src: /usr/bin/pip3
+      dest: /usr/bin/pip
+      state: link
+    register: result
+    retries: 3
+    delay: 5
+    until: result is not failed
+      
+  - name: Install Python packages
+    pip: "name={{ item }} state=present"
     with_items:
       - PyMySQL
 
@@ -33,6 +58,25 @@
       state: started
       enabled: true
 
+  - name: Creation mysql file configuration
+    file:
+      path: "/root/.my.cnf"
+      state: touch
+
+  - name: Editing configuration file
+    replace:
+      path: /etc/mysql/mysql.conf.d/mysqld.cnf
+      regexp: '(.*bind-addres.*)'
+      replace: '#\1'
+
+  - name: Restart MySQL
+    service: name=mysql state=restarted
+
+  - name: Ensure MySQL started
+    service:
+      name: mysql
+      state: started
+
   - name: update mysql password for application account
     mysql_user:
       login_unix_socket: /var/run/mysqld/mysqld.sock
@@ -46,13 +90,10 @@
       priv: "*.*:ALL,GRANT"
 
   - name: Add the application database
-    mysql_db: name="{{ db_name }}" state=present
-
-  - name: Editing configuration file
-    replace:
-      path: /etc/mysql/mysql.conf.d/mysqld.cnf
-      regexp: '(.*bind-addres.*)'
-      replace: '#\1'
+    mysql_db: 
+      name: "{{ db_name }}"
+      state: present
+      login_unix_socket: /var/run/mysqld/mysqld.sock
 
   - name: Restart MySQL
-    service: name=mysql state=restarted
\ No newline at end of file
+    service: name=mysql state=restarted
diff --git a/Docker-services-templates/wordpress-play.tpl b/Docker-services-templates/wordpress-play.tpl
index 067e8a2..e417c30 100644
--- a/Docker-services-templates/wordpress-play.tpl
+++ b/Docker-services-templates/wordpress-play.tpl
@@ -3,7 +3,7 @@
   become: yes
 
   vars_files:
-    - wordpress-vars.yml
+    - vars.yml
 
   pre_tasks:
     - name: "Install packages"
@@ -11,12 +11,47 @@
       with_items:
 ###OS_PACKETS###
 
+    - name: Remove a symbolic link
+      ansible.builtin.file: 
+        path: /usr/bin/python
+        state: absent
+
+    - name: Create a symbolic link
+      ansible.builtin.file: 
+        src: /usr/bin/python3
+        dest: /usr/bin/python
+        state: link
+      register: result
+      retries: 3
+      delay: 5
+      until: result is not failed
+
+    - name: Create a symbolic link
+      ansible.builtin.file: 
+        src: /usr/bin/pip3
+        dest: /usr/bin/pip
+        state: link
+      register: result
+      retries: 3
+      delay: 5
+      until: result is not failed
+    
     - name: "Install Python packages"
       pip: "name={{ item }}  state=present"
       with_items:
         - docker
 
+    - name: edit firewall
+      service:
+        name: ufw
+        state: stopped
+        enabled: false
+        
   tasks:
+    - name: Create a volume
+      community.docker.docker_volume:
+        name: mydata
+        
     - name: Start a WP container
       community.docker.docker_container:
         name: wordpress
@@ -30,5 +65,5 @@
           WORDPRESS_TABLE_PREFIX: "{{WORDPRESS_TABLE_PREFIX}}"
         ports:
           - "8080:80"
-        volumes_from:
+        volumes:
           - mydata
\ No newline at end of file
diff --git a/ansibleUtils.py b/ansibleUtils.py
index 020f2c4..c43cf11 100644
--- a/ansibleUtils.py
+++ b/ansibleUtils.py
@@ -25,7 +25,7 @@ def service_wordpress(template_list, template_data, kind):
         new_template_list = generic_matcher(template_list, template_data[kind])
     if kind == "play":
         if template_data[kind]["OS"] == "debian":
-            specific_data = {"OS": "apt", "OS_PACKETS": "        - docker\n        - docker.io"}
+            specific_data = {"OS": "apt", "OS_PACKETS": "        - python3\n        - python3-pip\n        - docker\n        - docker.io"}
         elif template_data[kind]["OS"] == "centos":
             specific_data = {"OS": "yum", "OS_PACKETS": "        - docker"}
         new_template_list = generic_matcher(template_list, specific_data)
-- 
GitLab