Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### Playbook ####
- ---
- - name : "Wordpress LAMP installation"
- hosts: staging
- become: true
- vars_files:
- - apache.vars
- - mariadb.vars
- - wordpress.vars
- tasks:
- - name: "Installing Apache and php-fpm"
- yum:
- name: "{{ packages }}"
- state: present
- register: package_status
- tags:
- - never
- - lamp
- - name: "Copying the httpd conf template to the remote machine"
- template:
- src: ./httpd.conf.tmpl
- dest: /etc/httpd/conf/httpd.conf
- register: conf_status
- tags:
- - never
- - lamp
- - name: "Creating the document root /var/www/html/{{ httpd_site }}"
- file:
- path: "/var/www/html/{{ httpd_site }}"
- state: directory
- owner: "{{ httpd_owner }}"
- group: "{{ httpd_group }}"
- tags:
- - never
- - lamp
- - name: "Copying the virtual host template to /etc/httpd/conf.d/{{ httpd_site }}"
- template:
- src: ./virtualhost.conf.tmpl
- dest: "/etc/httpd/conf.d/default.conf"
- register: virtualhost_status
- tags:
- - never
- - lamp
- - name: "Copying the contents to document root"
- when: package_status.changed == true
- copy:
- src: ./www/
- dest: "/var/www/html/{{ httpd_site }}"
- owner: "{{ httpd_owner }}"
- group: "{{ httpd_group }}"
- register: index_status
- tags:
- - never
- - lamp
- - name: "Service php-fpm restart/enable when condition meets"
- when: package_status.changed == true or index_status.changed == true
- service:
- name: php-fpm
- state: restarted
- enabled: true
- tags:
- - never
- - lamp
- - name: "Service httpd restart/enable when condition meets"
- when: package_status.changed == true or conf_status.changed == true or virtualhost_status.changed == true
- service:
- name: httpd
- state: restarted
- enabled: true
- tags:
- - never
- - lamp
- - name: "Installing mariadb required packages"
- yum:
- name: "{{ mysql_packages }}"
- state: present
- tags:
- - never
- - lamp
- - mysql
- register: mysql_packages
- - name: "Restarting mariadb server"
- when: mysql_packages.changed == true
- service:
- name: mariadb
- state: restarted
- enabled: true
- tags:
- - never
- - lamp
- - mysql
- - name: "Creating a new directory to copy the {{ mysql_docroot }}"
- file:
- path: /var/lib/new
- state: directory
- owner: mysql
- group: mysql
- tags:
- - never
- - lamp
- - mysql
- - name: "Copy the {{ mysql_docroot }} to /var/lib/new"
- when: mysql_packages.changed == true
- copy:
- src: "{{ mysql_docroot }}/"
- dest: /var/lib/new
- remote_src: true
- tags:
- - never
- - lamp
- - mysql
- - name: "Adding a filesystem ext4 to {{ mysql_docroot }}"
- filesystem:
- fstype: ext4
- dev: /dev/xvdb
- state: present
- tags:
- - never
- - lamp
- - mysql
- - name: "Adding {{ mysql_docroot }} it to fstab"
- mount:
- path: "{{ mysql_docroot }}/"
- src: /dev/xvdb
- fstype: ext4
- state: mounted
- tags:
- - never
- - lamp
- - mysql
- - name: "Copy the {{ mysql_docroot }} to /var/lib/new"
- when: mysql_packages.changed == true
- copy:
- src: /var/lib/new/
- dest: "{{ mysql_docroot }}"
- owner: mysql
- group: mysql
- remote_src: true
- tags:
- - never
- - lamp
- - mysql
- - name: "Installing the pip3 module for mysql"
- pip:
- name: PyMySQL
- state: present
- tags:
- - never
- - lamp
- - mysql
- - name: "Restarting mariadb server"
- when: mysql_packages.changed == true
- service:
- name: mariadb
- state: restarted
- enabled: true
- tags:
- - never
- - lamp
- - mysql
- - name: "Setting root password for mysql"
- mysql_user:
- login_user: root
- login_password: ""
- login_unix_socket: "{{ mysql_docroot }}/mysql.sock"
- name: root
- password: "{{ mysqlrootpasswd }}"
- ignore_errors: true
- tags:
- - never
- - lamp
- - mysql
- - name: "Creating a datababe {{ blog_db }}"
- mysql_db:
- login_user: root
- login_password: "{{ mysqlrootpasswd }}"
- login_unix_socket: "{{ mysql_docroot }}/mysql.sock"
- name: "{{ blog_db }}"
- tags:
- - never
- - lamp
- - mysql
- - name: "Creating an extra user {{ blog_user }}"
- mysql_user:
- login_user: root
- login_password: "{{ mysqlrootpasswd }}"
- login_unix_socket: "{{ mysql_docroot }}/mysql.sock"
- name: "{{ blog_user}}"
- password: "{{ blog_passwd }}"
- host: "%"
- priv: "{{ blog_db }}.*:ALL"
- tags:
- - never
- - lamp
- - mysql
- - name: "Wget the wordpress"
- get_url:
- url: "{{ wordpress_url }}"
- dest: /tmp/wordpress.tar.gz
- tags:
- - never
- - wordpress
- - name: "unarchive the worpress url"
- unarchive:
- src: /tmp/wordpress.tar.gz
- dest: /tmp/
- remote_src: true
- tags:
- - never
- - wordpress
- - name: "Copying the wordpress contents to the docroot"
- copy:
- src: /tmp/wordpress/
- dest: "/var/www/html/{{ httpd_site }}"
- owner: "{{ httpd_owner }}"
- group: "{{ httpd_group }}"
- remote_src: true
- tags:
- - never
- - wordpress
- - name: "Copying wp-config.php to remote server"
- template:
- src: ./wp-config.php.tmpl
- dest: "/var/www/html/{{ httpd_site }}/wp-config.php"
- owner: "{{ httpd_owner }}"
- group: "{{ httpd_group }}"
- tags:
- - never
- - wordpress
- - name: "Cleanup"
- file:
- name: "{{ item }}"
- state: absent
- with_items:
- - /tmp/wordpress.tar.gz
- - /tmp/wordpress
- - /var/lib/new
- tags:
- - never
- - wordpress
- #### Output ####
- [ec2-user@ip-172-31-45-107 ~]$ ansible-playbook -i inventory main.yml -t lamp,mysql,wordpress --vault-password-file=passwd.sh
- PLAY [Wordpress LAMP installation] *************************************************************************************************************************
- TASK [Gathering Facts] *************************************************************************************************************************************[WARNING]: Platform linux on host 172.31.40.182 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python
- interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more
- information.
- ok: [172.31.40.182]
- TASK [Installing Apache and php-fpm] ***********************************************************************************************************************changed: [172.31.40.182]
- TASK [Copying the httpd conf template to the remote machine] ***********************************************************************************************changed: [172.31.40.182]
- TASK [Creating the document root /var/www/html/blog.chrisich.fun] ******************************************************************************************changed: [172.31.40.182]
- TASK [Copying the virtual host template to /etc/httpd/conf.d/blog.chrisich.fun] ****************************************************************************changed: [172.31.40.182]
- TASK [Copying the contents to document root] ***************************************************************************************************************changed: [172.31.40.182]
- TASK [Service php-fpm restart/enable when condition meets] *************************************************************************************************changed: [172.31.40.182]
- TASK [Service httpd restart/enable when condition meets] ***************************************************************************************************changed: [172.31.40.182]
- TASK [Installing mariadb required packages] ****************************************************************************************************************changed: [172.31.40.182]
- TASK [Restarting mariadb server] ***************************************************************************************************************************changed: [172.31.40.182]
- TASK [Creating a new directory to copy the /var/lib/mysql] *************************************************************************************************changed: [172.31.40.182]
- TASK [Copy the /var/lib/mysql to /var/lib/new] *************************************************************************************************************changed: [172.31.40.182]
- TASK [Adding a filesystem ext4 to /var/lib/mysql] **********************************************************************************************************changed: [172.31.40.182]
- TASK [Adding /var/lib/mysql it to fstab] *******************************************************************************************************************changed: [172.31.40.182]
- TASK [Copy the /var/lib/mysql to /var/lib/new] *************************************************************************************************************changed: [172.31.40.182]
- TASK [Installing the pip3 module for mysql] ****************************************************************************************************************changed: [172.31.40.182]
- TASK [Restarting mariadb server] ***************************************************************************************************************************changed: [172.31.40.182]
- TASK [Setting root password for mysql] *********************************************************************************************************************changed: [172.31.40.182]
- TASK [Creating a datababe blog_db] *************************************************************************************************************************changed: [172.31.40.182]
- TASK [Creating an extra user blog_user] ********************************************************************************************************************changed: [172.31.40.182]
- TASK [Wget the wordpress] **********************************************************************************************************************************changed: [172.31.40.182]
- TASK [unarchive the worpress url] **************************************************************************************************************************changed: [172.31.40.182]
- TASK [Copying the wordpress contents to the docroot] *******************************************************************************************************changed: [172.31.40.182]
- TASK [Copying wp-config.php to remote server] **************************************************************************************************************changed: [172.31.40.182]
- TASK [Cleanup] *********************************************************************************************************************************************changed: [172.31.40.182] => (item=/tmp/wordpress.tar.gz)
- changed: [172.31.40.182] => (item=/tmp/wordpress)
- changed: [172.31.40.182] => (item=/var/lib/new)
- PLAY RECAP *************************************************************************************************************************************************172.31.40.182 : ok=25 changed=24 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- #### Verification ####
- [ec2-user@ip-172-31-40-182 ~]$ lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- xvda 202:0 0 8G 0 disk
- ├─xvda1 202:1 0 8G 0 part /
- ├─xvda127 259:0 0 1M 0 part
- └─xvda128 259:1 0 10M 0 part
- xvdb 202:16 0 5G 0 disk /var/lib/mysql
- [ec2-user@ip-172-31-40-182 ~]$
- [ec2-user@ip-172-31-40-182 ~]$
- [ec2-user@ip-172-31-40-182 ~]$ cat /etc/fstab
- #
- UUID=0bfb954f-5412-4d5a-8d40-3a2596532c79 / xfs defaults,noatime 1 1
- UUID=8EFE-43B9 /boot/efi vfat defaults,noatime,uid=0,gid=0,umask=0077,shortname=winnt,x-systemd.automount 0 2
- /dev/xvdb /var/lib/mysql/ ext4 defaults 0 0
- [ec2-user@ip-172-31-40-182 ~]$
- [ec2-user@ip-172-31-40-182 ~]$
- [ec2-user@ip-172-31-40-182 ~]$ ll /var/lib/mysql/
- total 122944
- -rw-rw----. 1 mysql mysql 24576 Jun 27 18:55 aria_log.00000001
- -rw-rw----. 1 mysql mysql 52 Jun 27 18:55 aria_log_control
- drwx------. 2 mysql mysql 4096 Jun 27 18:52 blog_db
- -rw-rw----. 1 mysql mysql 976 Jun 27 18:55 ib_buffer_pool
- -rw-rw----. 1 mysql mysql 100663296 Jun 27 18:55 ib_logfile0
- -rw-rw----. 1 mysql mysql 12582912 Jun 27 18:55 ibdata1
- -rw-rw----. 1 mysql mysql 12582912 Jun 27 18:55 ibtmp1
- drwx------. 2 mysql mysql 16384 Jun 27 18:52 lost+found
- -rw-rw----. 1 mysql mysql 0 Jun 27 18:52 multi-master.info
- drwx------. 2 mysql mysql 4096 Jun 27 18:52 mysql
- srwxrwxrwx. 1 mysql mysql 0 Jun 27 18:55 mysql.sock
- -rw-rw----. 1 mysql mysql 16 Jun 27 18:52 mysql_upgrade_info
- drwx------. 2 mysql mysql 4096 Jun 27 18:52 performance_schema
Advertisement
Add Comment
Please, Sign In to add comment