공부합시다!/Ansible
Ansible: wordpress + RDS (AWS 환경)
간서치
2022. 7. 10. 10:09
728x90
이번 차수에서는 wordpress를 Ansible 구성 후 이미 생성되어 있는 AWS RDS와 연동하는 작업입니다.
AWS를 사용하지 않는 경우에는 별도로 mysql등을 설치하셔서 이용하시면 되세요.
EndPoint를 IP로 설정하셔도 무방합니다.
---
- name: Wordpress Install & Configuration
hosts: web
gather_facts: false
ignore_errors: true
tasks:
- name: yum install http
yum:
name: httpd
state: present
- name: amzn2 enable php7.2
shell:
cmd: 'amazon-linux-extras enable php7.2 lamp-mariadb10.2-php7.2'
- name: yum install php* mariadb
yum:
name:
- php-cli
- php-pdo
- php-fpm
- php-json
- php-mysqlnd
- mariadb
- php
state: present
- name: get_url wordpress
get_url:
url: 'https://ko.wordpress.org/latest-ko_KR.tar.gz'
dest: './'
- name: unarchive
unarchive:
src: './wordpress-5.8.2-ko_KR.tar.gz'
dest: './'
remote_src: yes
- name: wordpress file copy dest /var/www/html
copy:
src: '/root/wordpress/'
dest: '/var/www/html/'
remote_src: yes
# shell: 'cp -a /root/wordpress/* /var/www/html/'
- name: chown
# file:
# path: '/var/www/html/*'
# owner: apache
# group: apache
shell:
cmd: 'chown -R apache.apache /var/www/html/'
- name: file copy wp-config.php
copy:
src: '/var/www/html/wp-config-sample.php'
dest: '/var/www/html/wp-config.php'
remote_src: yes
- name: change syntax DirectoryIndex
replace:
path: '/etc/httpd/conf/httpd.conf'
regexp: 'DirectoryIndex index.html'
replace: 'DirectoryIndex index.php'
- name: change syntax database_name_here
replace:
path: '/var/www/html/wp-config.php'
regexp: 'database_name_here'
replace: 'mydb'
- name: change syntax username_here
replace:
path: '/var/www/html/wp-config.php'
regexp: 'username_here'
replace: 'admin'
- name: change syntax password_here
replace:
path: '/var/www/html/wp-config.php'
regexp: 'password_here'
replace: 'It12345!'
- name: change syntax localhost
replace:
path: '/var/www/html/wp-config.php'
regexp: 'localhost'
replace: 'mydb.xxxxxxxxx.ap-northeast-2.rds.amazonaws.com'
# replace 부분에 IP Address 사용해도 무방
- name: make file
file:
path: '/var/www/html/health.html'
state: touch
- name: copy contents
copy:
content: |
<html>
<body>
<h1>SDKIM_WEBSERVER-1</h1>
</body>
<html>
dest: '/var/www/html/health.html'
- name: systemctl start httpd & systemctl enable httpd
systemd:
name: httpd
state: started
enabled: yes
AWS에서 Linux 인스턴스에 wordpress + php 설치 후 기존 RDS와 연결하는 작업이었습니다.
이 정도 Code만 해내셔도 다른 작업들은 다 참고해서 하실 수 있으실 겁니다.
Have a nice day!
728x90