---
- hosts: centos8_init
user: ioniere
become: yes
vars:
db_passwd: secret
tasks:
- name: nginx 설치
yum:
name: nginx
state: latest
- name: mariadb 설치
yum:
name: ['mariadb-server', 'mariadb']
state: latest
- name: php 설치
yum:
name: ['php-bcmath', 'php-cli', 'php-common', 'php-dba', 'php-dbg', 'php-devel', 'php-embedded', 'php-enchant', 'php-fpm', 'php-gd', 'php-gmp', 'php-intl', 'php-json', 'php-ldap', 'php-mbstring', 'php-mysqlnd', 'php-odbc', 'php-opcache', 'php-pdo', 'php-pear', 'php-pecl-apcu', 'php-pecl-apcu-devel', 'php-pecl-zip', 'php-pgsql', 'php-process', 'php-recode', 'php-snmp', 'php-soap', 'php-xml', 'php-xmlrpc']
state: latest
- name: nginx.conf 복사
get_url:
url: http://data.yeonghoon.kim/centos8_npm/source/nginx.conf
dest: /etc/nginx/nginx.conf
force: yes
- name: nginx fastcgi_params 복사
get_url:
url: http://data.yeonghoon.kim/centos8_npm/source/fastcgi_params
dest: /etc/nginx/fastcgi_params
force: yes
- name: nginx virtualhost.conf_sample 복사
get_url:
url: http://data.yeonghoon.kim/centos8_npm/source/virtualhost_sample_conf
dest: /etc/nginx/conf.d/virtualhost_sample_conf
force: yes
- name: mariadb-server.cnf(my.cnf) 복사
get_url:
url: http://data.yeonghoon.kim/centos8_npm/source/mariadb-server.cnf
dest: /etc/my.cnf.d/mariadb-server.cnf
force: yes
- name: php.ini 복사
get_url:
url: http://data.yeonghoon.kim/centos8_npm/source/php.ini
dest: /etc/php.ini
force: yes
- name: php-fpm.conf 복사
get_url:
url: http://data.yeonghoon.kim/centos8_npm/source/php-fpm.conf
dest: /etc/php-fpm.conf
force: yes
- name: www.conf(php-fpm) 복사
get_url:
url: http://data.yeonghoon.kim/centos8_npm/source/www.conf
dest: /etc/php-fpm.d/www.conf
force: yes
- name: test 디비 존재유무 확인(mysql_install_secure.sql 실행 유무 판단)
stat:
path: /var/lib/mysql/test
register: test_db_check
- name: mysql_secure_install.sql 파일 복사
get_url:
url: http://data.yeonghoon.kim/centos8_npm/source/mysql_secure_install.sql
dest: /tmp/mysql_secure_install.sql
force: yes
when: test_db_check.stat.exists == False
- name: php 구동
service:
name: php-fpm
state: started
enabled: yes
- name: nginx 구동 및 부팅 시 구동되도록 설정
service:
name: nginx
state: started
enabled: yes
- name: mariadb 구동 및 부팅 시 구동되도록 설정
service:
name: mariadb
state: started
enabled: yes
- name: mysql 루트 패스워드 설정
lineinfile:
path: /tmp/mysql_secure_install.sql
regexp: '^UPDATE'
line: "UPDATE mysql.user SET Password=PASSWORD('{{ db_passwd }}') WHERE User='root';"
when: test_db_check.stat.exists == False
- name: mysql_secure_install.sql 실행
shell: mysql -sfu root < /tmp/mysql_secure_install.sql
when: test_db_check.stat.exists == False
- name: mysql_secure_install.sql 삭제
file:
path: /tmp/mysql_secure_install.sql
state: absent
when: test_db_check.stat.exists == False
host, user, db_passwd는 상황에 맞게 수정 후 사용
방화벽 설정은 별도로 진행