Resources attached to the Road To DevOps tutorial https://blog.noobtoroot.xyz/road-to-devops/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

149 lines
3.6 KiB

---
- hosts: ansible-2
vars:
- DB_NAME: wordpress
- DB_USER: wordpressuser
- DB_PASSWORD: "12345"
- DB_HOST: "{{ hostvars['ansible-2']['ansible_ssh_host'] }}"
- WEB_HOST: "{{ hostvars['ansible-1']['ansible_ssh_host'] }}"
tasks:
- name: Installation of mariadb-server package
yum:
name: mariadb-server
state: present
update_cache: yes
- name: Ensure mariadb-server is running (and enabled at boot)
service:
name: mariadb
state: started
enabled: yes
- name: Installation of MySQL-python package
# package required to use ansible mysql modules
yum:
name: MySQL-python
state: present
update_cache: yes
- name: Create a new database with name '{{ DB_NAME }}'
mysql_db:
name: '{{ DB_NAME }}'
state: present
- name: Create a new database user with name '{{ DB_USER }}'
mysql_user:
name: '{{ DB_USER }}'
password: '{{ DB_PASSWORD }}'
priv: '{{ DB_NAME }}.*:ALL'
host: '{{ WEB_HOST }}'
state: present
- name: Allow mariadb traffic on port 3306
firewalld:
service: mysql
permanent: true
state: enabled
immediate: yes
- hosts: ansible-1
vars:
- DB_NAME: wordpress
- DB_USER: wordpressuser
- DB_PASSWORD: "12345"
- DB_HOST: "{{ hostvars['ansible-2']['ansible_ssh_host'] }}"
tasks:
- name: Installation of apache package
dnf:
name: httpd
state: present
update_cache: yes
- name: Installation of php package
dnf:
name: php
state: present
update_cache: yes
- name: Installation of php-mysqlnd package
dnf:
name: php-mysqlnd
state: present
update_cache: yes
notify: Reload Apache
- name: Installation of wget package
dnf:
name: wget
state: present
update_cache: yes
- name: Ensure apache is running (and enabled at boot)
service:
name: httpd
state: started
enabled: yes
- name: Download wordpress archive
get_url:
url: https://wordpress.org/wordpress-5.0.8.tar.gz
dest: /var/www/html/wordpress.tar.gz
mode: 0440
- name: Untar wordpress archive
unarchive:
src: /var/www/html/wordpress.tar.gz
dest: /var/www/html
remote_src: true
- name: Remove wordpress archive
file:
path: /var/www/html/wordpress.tar.gz
state: absent
- name: Create wordpress configuration file
copy:
src: /var/www/html/wordpress/wp-config-sample.php
dest: /var/www/html/wordpress/wp-config.php
remote_src: true
- name: Update wordpress configuration file with db name
replace:
dest: /var/www/html/wordpress/wp-config.php
regexp: 'database_name_here'
replace: '{{ DB_NAME }}'
- name: Update wordpress configuration file with user name
replace:
dest: /var/www/html/wordpress/wp-config.php
regexp: 'username_here'
replace: '{{ DB_USER }}'
- name: Update wordpress configuration file with user password
replace:
dest: /var/www/html/wordpress/wp-config.php
regexp: 'password_here'
replace: '{{ DB_PASSWORD }}'
- name: Update wordpress configuration file with host
replace:
dest: /var/www/html/wordpress/wp-config.php
regexp: 'localhost'
replace: '{{ DB_HOST }}'
- name: Allow http traffic on port 80
firewalld:
service: http
permanent: true
state: enabled
immediate: yes
handlers:
- name: Reload Apache
service:
name: httpd
state: restarted