Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - hosts: testservers
- tasks:
- - name: Installing VM Ware Tools
- yum: name=open-vm-tools state=present
- when: ansible_distribution == "CentOS"
- - name: Installing VM Ware Tools Suse
- zypper: name=https://packages.vmware.com/tools/esx/latest/repos/vmware-tools-repo-SLES{{ ansible_distribution_major_version }}.{{ ansible_distribution_release }}-latest.sles{{ ansible_distribution_major_version }}.{{ ansible_architecture }}.rpm
- when: ansible_os_family == "Suse"
- - name: VM Ware tools
- service: name=vmtoolsd.service state=restarted enabled=yes
- # when: ansible_distribution == "CentOS" and ansible_virtualization_type =="VMware"
- - hosts: testservers
- vars:
- db_name: wordpress
- db_user: wpuser
- db_password: P@ssw0rd
- tasks:
- #### SYSTEM UPDATE ####
- # CentOS #
- - name: System Update CentOS
- yum: name=* state=latest
- when: ansible_distribution == "CentOS"
- - name: Disable SELinux CentOS
- selinux: state=disabled
- when: ansible_distribution == "CentOS"
- - name: Installing epel-rep CentOS
- yum: pkg=epel-release state=latest
- when: ansible_distribution == "CentOS"
- # SUSE #
- - name: System Update Suse
- zypper: name=* state=latest
- when: ansible_os_family == "Suse"
- - name: Apply all patches Suse
- zypper: name=* state=latest type=patch
- when: ansible_os_family == "Suse"
- # ALL OS #
- - name: Reboot server
- shell: sleep 3 && /sbin/shutdown -r "Ansible system reboot"
- # async: 1
- poll: 0
- - name: Waiting for SSH connection
- local_action: wait_for host={{ inventory_hostname }} port=22 delay=20 connect_timeout=200
- become: false
- delegate_to: localhost
- #### Software Installation ####
- - name: Installation Utils CentOS
- yum: pkg={{ item }}
- with_items:
- - wget
- - mc
- - nano
- when: ansible_distribution == "CentOS"
- - name: Installation Utils Suse
- zypper: pkg={{ item }}
- with_items:
- - wget
- - mc
- when: ansible_os_family == "Suse"
- #### APACHE ####
- # CentOS #
- - name: Installation Apache Suse
- yum: pkg=httpd state=present
- when: ansible_distribution == "CentOS"
- - name: Enable Apache on System Boot CentOS
- service: name=httpd enabled=yes
- when: ansible_distribution == "CentOS"
- # Suse #
- - name: Installation Apache Suse
- zypper: name=apache2 state=latest
- when: ansible_os_family == "Suse"
- - name: Enable Apache on System Boot Suse
- service: name=apache2 enabled=yes
- when: ansible_os_family == "Suse"
- #### PHP ####
- # CentOS #
- - name: Installation PHP mods CentOS
- yum: pkg={{ item }} state=present
- with_items:
- - php
- - php-gd
- - php-mysql
- - php-devel
- when: ansible_distribution == "CentOS"
- # Suse #
- - name: Installation PHP mods Suse
- zypper: pkg={{ item }} state=present
- with_items:
- - php
- - php-mysql
- - php-gd
- when: ansible_os_family == "Suse"
- #### MariaDB - CentOS ####
- - name: Installation MariaDB CentOS
- yum: pkg=mariadb-server state=present
- when: ansible_distribution == "CentOS"
- - name: Enable MariaDB on System Boot CentOS
- service: name=mariadb enabled=yes
- when: ansible_distribution == "CentOS"
- - name: Installation Pyton Mysql module CentOS
- yum: pkg=MySQL-python state=present
- when: ansible_distribution == "CentOS"
- #### MySQL - Suse ####
- - name: Installation MySQL server Suse
- zypper: pkg=mysql state=present
- when: ansible_os_family == "Suse"
- - name: Installation MySQL client Suse
- zypper: pkg=mysql-client state=present
- when: ansible_os_family == "Suse"
- - name: Enable MySQL server on System Boot Suse
- service: name=mysql enabled=yes
- when: ansible_os_family == "Suse"
- - name: Install Phyton-MySQL module Suse
- zypper: pkg=python-mysql state=present
- when: ansible_os_family == "Suse"
- #### phpMyAdmin ####
- # CentOS #
- - name: Installation phpMyAdmin
- yum: pkg=phpMyAdmin state=present
- when: ansible_distribution == "CentOS"
- # Suse #
- # - name: Installation phpMyAdmin Suse
- # zypper: pkg=phpMyAdmin
- # when: ansible_os_family == "Suse"
- #### Starting services ####
- # CentOS #
- - name: Service Mariadb start CentOS
- service: name=mariadb state=started
- when: ansible_distribution == "CentOS"
- - name: Service Apache start CentOS
- service: name=httpd state=started
- when: ansible_distribution == "CentOS"
- # Suse #
- - name: Service MySQL start Suse
- service: name=mysql state=started
- when: ansible_os_family == "Suse"
- - name: Service Apache start Suse
- service: name=apache2 state=started
- when: ansible_os_family == "Suse"
- #### Configuring MariaDB and SQL !!! ALL OS !!! ####
- - name: Set root Password
- mysql_user: user=root password=P@ssw0rd host=localhost
- #when: ansible_distribution == "CentOS"
- - name: Create MySQL database
- mysql_db: name={{ db_name }} login_user=root login_password=P@ssw0rd state=present
- #when: ansible_distribution == "CentOS"
- - name: Create MySQL user
- mysql_user: login_user=root login_password=P@ssw0rd name={{ db_user }} password={{ db_password }} priv=*.*:ALL
- #when: ansible_distribution == "CentOS"
- #### WordPress ####
- # ALL OS #
- - name: Download LAST version WordPress
- get_url: url=https://wordpress.org/latest.tar.gz dest=/tmp/wordpress.tar.gz validate_certs=no
- #when: ansible_distribution == "CentOS"
- # CentOS #
- - name: Extract WordPress CentOS
- unarchive: src=/tmp/wordpress.tar.gz dest=/var/www/html copy=no
- when: ansible_distribution == "CentOS"
- # Suse #
- - name: Extract WordPress Suse
- unarchive: src=/tmp/wordpress.tar.gz dest=/srv/www/htdocs copy=no
- when: ansible_os_family == "Suse"
- #### WordPress Config ####
- # CentOS #
- - name: Create WordPress config file CentOS
- command: mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php creates=/var/www/html/wordpress/wp-config.php
- when: ansible_distribution == "CentOS"
- - name: Update WordPress config file CentOS
- lineinfile:
- dest=/var/www/html/wordpress/wp-config.php
- regexp="{{ item.regexp }}"
- line="{{ item.line }}"
- with_items:
- - {'regexp': "define\\('DB_NAME', '(.)+'\\);", 'line': "define('DB_NAME', '{{ db_name }}');"}
- - {'regexp': "define\\('DB_USER', '(.)+'\\);", 'line': "define('DB_USER', '{{ db_user }}');"}
- - {'regexp': "define\\('DB_PASSWORD'. '(.)+'\\);", 'line': "define('DB_PASSWORD', '{{ db_password }}');"}
- when: ansible_distribution == "CentOS"
- # Suse #
- - name: Create WordPress config file Suse
- command: mv /srv/www/htdocs/wordpress/wp-config-sample.php /srv/www/htdocs/wordpress/wp-config.php creates=/var/www/html/wordpress/wp-config.php
- when: ansible_os_family == "Suse"
- - name: Update WordPress config file Suse
- lineinfile:
- dest=/srv/www/htdocs/wordpress/wp-config.php
- regexp="{{ item.regexp }}"
- line="{{ item.line }}"
- with_items:
- - {'regexp': "define\\('DB_NAME', '(.)+'\\);", 'line': "define('DB_NAME', '{{ db_name }}');"}
- - {'regexp': "define\\('DB_USER', '(.)+'\\);", 'line': "define('DB_USER', '{{ db_user }}');"}
- - {'regexp': "define\\('DB_PASSWORD'. '(.)+'\\);", 'line': "define('DB_PASSWORD', '{{ db_password }}');"}
- when: ansible_os_family == "Suse"
- #### Firewall Config ####
- # CentOS #
- - name: Add HTTP service CentOS
- command: firewall-cmd --add-service=http --permanent
- when: ansible_distribution == "CentOS"
- - name: Add HTTPs service CentOS
- command: firewall-cmd --add-service=https --permanent
- when: ansible_distribution == "CentOS"
- - name: Add MySQL service CentOS
- command: firewall-cmd --add-port=3306/tcp --permanent
- when: ansible_distribution == "CentOS"
- - name: Restarting firewall CentOS
- command: firewall-cmd --reload
- when: ansible_distribution == "CentOS"
- # Suse #
- - name: Add HTTP service Suse
- lineinfile: dest=/etc/sysconfig/SuSEfirewall2 line='FW_CONFIGURATIONS_EXT="apache2"' create="yes"
- when: ansible_os_family == "Suse"
- - name: Add SSH servcie Suse
- lineinfile: dest=/etc/sysconfig/SuSEfirewall2 line='FW_SERVICES_EXT_TCP="ssh"' create="yes"
- when: ansible_os_family == "Suse"
- - name: Add MySQL servcie Suse
- lineinfile: dest=/etc/sysconfig/SuSEfirewall2 line='FW_SERVICES_EXT_TCP="3306"' create="yes"
- when: ansible_os_family == "Suse"
- - name: Allow ping Suse
- lineinfile: dest=/etc/sysconfig/SuSEfirewall2 line='FW_ALLOW_PING_FW="yes"' create="yes"
- when: ansible_os_family == "Suse"
- - name: Reload init Firewall settings Suse
- command: /etc/init.d/SuSEfirewall2_init restart
- when: ansible_os_family == "Suse"
- - name: Reload init Firewall settings Suse
- command: /etc/init.d/SuSEfirewall2_init restart
- when: ansible_os_family == "Suse"
- #### Services ####
- # CentOS #
- - name: MariaDB restart CentOS
- service: name=mariadb state=restarted
- when: ansible_distribution == "CentOS"
- - name: Apache restart CentOS
- service: name=httpd state=restarted
- when: ansible_distribution == "CentOS"
- # Suse #
- - name: MySQL restart Suse
- service: name=mysql state=restarted
- when: ansible_distribution == "Suse"
- - name: Apache restart Suse
- service: name=apache2 state=restarted
- when: ansible_distribution == "Suse"
- - hosts: testservers
- vars:
- vmwaretools_tools_version: latest
- vmwaretools_yum_server: https://packages.vmware.com
- vmwaretools_yum_path: /tools
- vmwaretools_repo_version: latest
- tasks:
- - name: Downloading file
- get_url: url={{ vmwaretools_yum_server }}{{ vmwaretools_yum_path }}/esx/{{ vmwaretools_tools_version }}/repos/vmware-tools-repo-SELS{{ ansible_distribution_major_version }}.{{ ansible_distribution_release }}-{{ vmwaretools_repo_version }}.sles{{ ansible_distribution_major_version }}.{{ ansible_architecture }}.rpm dest=/tmp/vmtools.rpm validate_certs=no
- when: ansible_os_family == "Suse" and ansible_distribution_major_version|int == 11
- - hosts: testservers
- tasks:
- ##### Firewall config #####
- ## CentOS ##
- - name: Allow HTTP CentOS
- command: firewall-cmd --add-service=http --permanent
- when: ansible_distribution == "CentOS"
- - name: Allow HTTPs CentOS
- command: firewall-cmd --add-service=https --permanent
- when: ansible_distribution == "CentOS"
- - name: Allow SQL CentOS
- command: firewall-cmd --add-port=3306/tcp --permanent
- when: ansible_distribution == "CentOS"
- ## SUSE ##
- - name: Allow HTTP SUSE
- lineinfile: dest=/etc/sysconfig/SuSEfirewall2 line='FW_CONFIGURATIONS_EXT="apache2"' create=yes
- when: ansible_os_family == "Suse"
- - name: Allow SSH SUSE
- lineinfile: dest=/etc/sysconfig/SuSEfirewall2 line='FW_SERVICES_EXT_TCP="ssh"' create=yes
- when: ansible_os_family == "Suse"
- - name: Allow PING SUSE
- lineinfile: dest=/etc/sysconfig/SuSEfirewall2 line='FW_ALLOW_PING_FW="yes"' create=yes
- when: ansible_os_family == "Suse"
- ###### Firewall restart ######
- - name: Reload firewall service CentOS
- command: firewall-cmd --reload
- when: ansible_distribution == "CentOS"
- - name: Reload init firewall service SUSE
- command: /etc/init.d/SuSEfirewall2_init restart
- when: ansible_os_family == "Suse"
- - name: Reload setup firewall service SUSE
- command: /etc/init.d/SuSEfirewall2_setup restart
- when: ansible_os_family == "Suse"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement