728x90
구성과정은 Ad-Hoc으로 WordPress 구성부터 원복까지 와 동일하고, 같은 내용을 playbook(.yaml)으로 작성한 것임
📌INDEX
✔️ 기본 Playbook + revert 과정
wordpress.yaml
- hosts: wp
tasks:
- yum:
name: https://rpms.remirepo.net/enterprise/remi-release-7.rpm
state: present
validate_certs: no
- yum_repository:
name: remi-safe
file: remi-safe
mirrorlist: http://cdn.remirepo.net/enterprise/7/safe/mirror
description: remi-safe
enabled: no
- yum_repository:
name: remi-php74
file: remi-php74
mirrorlist: http://cdn.remirepo.net/enterprise/7/php74/mirror
description: remi-php74
enabled: yes
gpgcheck: yes
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
- yum:
name: httpd,php,php-mysqlnd,mariadb,mariadb-server,python2-PyMySQL
state: installed
- service:
name: httpd
state: started
enabled: yes
- service:
name: mariadb
state: started
enabled: yes
- get_url:
url: https://wordpress.org/wordpress-5.9.3.tar.gz
dest: /home/vagrant
- unarchive:
src: /home/vagrant/wordpress-5.9.3.tar.gz
remote_src: yes
dest: /var/www/html
owner: apache
group: apache
- mysql_db:
name: wordpress
state: present
login_user: root
- mysql_user:
name: wpadm
password: P@ssw0rd
state: present
login_user: root
priv: "wordpress.*:ALL"
- copy:
src: /var/www/html/wordpress/wp-config-sample.php
remote_src: yes
dest: /var/www/html/wordpress/wp-config.php
owner: apache
group: apache
- replace:
path: /var/www/html/wordpress/wp-config.php
regexp: database_name_here
replace: wordpress
- replace:
path: /var/www/html/wordpress/wp-config.php
regexp: username_here
replace: wpadm
- replace:
path: /var/www/html/wordpress/wp-config.php
regexp: password_here
replace: P@ssw0rd
원복하기
revert.yaml
- hosts: wp
tasks:
- service:
name: httpd
state: stopped
- service:
name: mariadb
state: stopped
- file:
path: /var/www/html/wordpress
state: absent
- file:
path: /home/vagrant/wordpress-5.9.3.tar.gz
state: absent
- yum:
name: httpd,php,php-mysqlnd,mariadb,mariadb-server,python2-PyMySQL
state: absent
autoremove: yes
- file:
name: /var/lib/mysql
state: absent
- yum:
name: remi-release
autoremove: yes
state: absent
✔️ vars로 작성
wordpress_with_vars.yaml
- hosts: wp
vars:
php:
remi_repo:
pkg: https://rpms.remirepo.net/enterprise/remi-release-7.rpm
safe_mirror: http://cdn.remirepo.net/enterprise/7/safe/mirror
php74_mirror: http://cdn.remirepo.net/enterprise/7/php74/mirror
gpgkey_path: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
wp_pkg: httpd,php,php-mysqlnd,mariadb,mariadb-server,python2-PyMySQL
wp_version: "5.9.3"
wp_file_name: 'wordpress-{{ wp_version }}.tar.gz'
wp_source_url: 'https://wordpress.org/{{ wp_file_name }}'
mysql:
dbname: wordpress
dbuser: wpadm
dbpwd: P@ssw0rd
tasks:
- yum:
name: '{{ php["remi_repo"]["pkg"] }}'
state: present
validate_certs: no
- yum_repository:
name: remi-safe
file: remi-safe
mirrorlist: '{{ php["remi_repo"]["safe_mirror"] }}'
description: remi-safe
enabled: no
- yum_repository:
name: remi-php74
file: remi-php74
mirrorlist: '{{ php["remi_repo"]["php74_mirror"] }}'
description: remi-php74
enabled: yes
gpgcheck: yes
gpgkey: '{{ php["remi_repo"]["gpgkey_path"] }}'
- yum:
name: "{{ wp_pkg }}"
state: installed
- service:
name: httpd
state: started
enabled: yes
- service:
name: mariadb
state: started
enabled: yes
- get_url:
url: '{{ wp_source_url }}'
dest: /home/vagrant
- unarchive:
src: '/home/vagrant/{{ wp_file_name }}'
remote_src: yes
dest: /var/www/html
owner: apache
group: apache
- mysql_db:
name: '{{ mysql["dbname"] }}'
state: present
login_user: root
- mysql_user:
name: '{{ mysql["dbuser"] }}'
password: '{{ mysql["dbpwd"] }}'
state: present
login_user: root
priv: '{{ mysql["dbname"] }}.*:ALL'
- copy:
src: /var/www/html/wordpress/wp-config-sample.php
remote_src: yes
dest: /var/www/html/wordpress/wp-config.php
owner: apache
group: apache
- replace:
path: /var/www/html/wordpress/wp-config.php
regexp: database_name_here
replace: '{{ mysql["dbname"] }}'
- replace:
path: /var/www/html/wordpress/wp-config.php
regexp: username_here
replace: '{{ mysql["dbuser"] }}'
- replace:
path: /var/www/html/wordpress/wp-config.php
regexp: password_here
replace: '{{ mysql["dbpwd"] }}'
▶️ vars 내용만 별도의 yaml 파일로 작성하여 참조하는 것도 가능
wordpress_vars.yaml
php:
remi_repo:
pkg: https://rpms.remirepo.net/enterprise/remi-release-7.rpm
safe_mirror: http://cdn.remirepo.net/enterprise/7/safe/mirror
php74_mirror: http://cdn.remirepo.net/enterprise/7/php74/mirror
gpgkey_path: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
wp_pkg: httpd,php,php-mysqlnd,mariadb,mariadb-server,python2-PyMySQL
wp_version: "5.9.3"
wp_file_name: 'wordpress-{{ wp_version }}.tar.gz'
wp_source_url: 'https://wordpress.org/{{ wp_file_name }}'
mysql:
dbname: wordpress
dbuser: wpadm
dbpwd: P@ssw0rd
wordpress_with_vars.yaml
- hosts: wp
vars_files:
- wordpress_vars.yaml
tasks:
- yum:
name: '{{ php["remi_repo"]["pkg"] }}'
state: present
validate_certs: no
- yum_repository:
name: remi-safe
file: remi-safe
mirrorlist: '{{ php["remi_repo"]["safe_mirror"] }}'
description: remi-safe
enabled: no
- yum_repository:
name: remi-php74
file: remi-php74
mirrorlist: '{{ php["remi_repo"]["php74_mirror"] }}'
description: remi-php74
enabled: yes
gpgcheck: yes
gpgkey: '{{ php["remi_repo"]["gpgkey_path"] }}'
- yum:
name: "{{ wp_pkg }}"
state: installed
- service:
name: httpd
state: started
enabled: yes
- service:
name: mariadb
state: started
enabled: yes
- get_url:
url: '{{ wp_source_url }}'
dest: /home/vagrant
- unarchive:
src: '/home/vagrant/{{ wp_file_name }}'
remote_src: yes
dest: /var/www/html
owner: apache
group: apache
- mysql_db:
name: '{{ mysql["dbname"] }}'
state: present
login_user: root
- mysql_user:
name: '{{ mysql["dbuser"] }}'
password: '{{ mysql["dbpwd"] }}'
state: present
login_user: root
priv: '{{ mysql["dbname"] }}.*:ALL'
- copy:
src: /var/www/html/wordpress/wp-config-sample.php
remote_src: yes
dest: /var/www/html/wordpress/wp-config.php
owner: apache
group: apache
- replace:
path: /var/www/html/wordpress/wp-config.php
regexp: database_name_here
replace: '{{ mysql["dbname"] }}'
- replace:
path: /var/www/html/wordpress/wp-config.php
regexp: username_here
replace: '{{ mysql["dbuser"] }}'
- replace:
path: /var/www/html/wordpress/wp-config.php
regexp: password_here
replace: '{{ mysql["dbpwd"] }}'
✔️ template 이용
replace 모듈의 반복적인 사용을 template으로 대체
- hosts: wp
vars_files:
- wordpress_vars.yaml
tasks:
- yum:
name: '{{ php["remi_repo"]["pkg"] }}'
state: present
validate_certs: no
- yum_repository:
name: remi-safe
file: remi-safe
mirrorlist: '{{ php["remi_repo"]["safe_mirror"] }}'
description: remi-safe
enabled: no
- yum_repository:
name: remi-php74
file: remi-php74
mirrorlist: '{{ php["remi_repo"]["php74_mirror"] }}'
description: remi-php74
enabled: yes
gpgcheck: yes
gpgkey: '{{ php["remi_repo"]["gpgkey_path"] }}'
- yum:
name: "{{ wp_pkg }}"
state: installed
- service:
name: httpd
state: started
enabled: yes
- service:
name: mariadb
state: started
enabled: yes
- get_url:
url: '{{ wp_source_url }}'
dest: /home/vagrant
- unarchive:
src: '/home/vagrant/{{ wp_file_name }}'
remote_src: yes
dest: /var/www/html
owner: apache
group: apache
- mysql_db:
name: '{{ mysql["dbname"] }}'
state: present
login_user: root
- mysql_user:
name: '{{ mysql["dbuser"] }}'
password: '{{ mysql["dbpwd"] }}'
state: present
login_user: root
priv: '{{ mysql["dbname"] }}.*:ALL'
- copy:
src: /var/www/html/wordpress/wp-config-sample.php
remote_src: yes
dest: /var/www/html/wordpress/wp-config.php
owner: apache
group: apache
- template:
src: wp-config.php.j2
dest: /var/www/html/wordpress/wp-config.php
728x90