ansible을 사용하여 여러 장치에 Wordpress를 자동으로 세팅할 수 있도록 설정
answp.yaml
---
- name: Install Wordpress
hosts: nodes
user: ansuser
become: yes
vars:
db_name: wpdb
db_user: wpuser
db_password: 1234
wp_dir: /var/www/html/wordpress
tasks:
- name: install packages
dnf:
name:
- httpd
- php
- php-gd
- php-xml
- php-mbstring
- php-json
- php-mysqlnd
- php-fpm
- mariadb-server
- wget
- unzip
state: present
- name: start and enable services
systemd:
name: "{{ item }}"
state: started
enabled: yes
loop:
- httpd
- mariadb
- name: create database and user
shell: |
mysql -u root -e "
create database if not exists wpdb;
create user if not exists wpuser@localhost IDENTIFIED BY '1234';
grant all on wpdb.* to wpuser@localhost;
flush privileges;
"
- name: download wordpress
get_url:
url: https://wordpress.org/latest.zip
dest: /tmp/wordpress.zip
- name: unzip wordpress
unarchive:
src: /tmp/wordpress.zip
dest: /var/www/html/
remote_src: yes
- name: copy wp-config.php
copy:
src: "{{ wp_dir }}/wp-config-sample.php"
dest: "{{ wp_dir }}/wp-config.php"
remote_src: yes
- name: db_name
lineinfile:
path: "{{ wp_dir }}/wp-config.php"
regexp: "^define\\( 'DB_NAME'"
line: "define( 'DB_NAME', '{{ db_name }}' );"
- name: db_username
lineinfile:
path: "{{ wp_dir }}/wp-config.php"
regexp: "^define\\( 'DB_USER'"
line: "define( 'DB_USER', '{{ db_user }}' );"
- name: db_password
lineinfile:
path: "{{ wp_dir }}/wp-config.php"
regexp: "^define\\( 'DB_PASSWORD'"
line: "define( 'DB_PASSWORD', '{{ db_password }}' );"
- name: start firewalld
systemd:
name: firewalld
state: started
enabled: yes
- name: openfirewall
firewalld:
service: http
permanent: yes
state: enabled
immediate: yes
완료 후 해당 .yaml 파일 실행
ansible-playbook answp.yaml

갑분문제
rockylinux 8 버전의 Box를 통해 VirtualBox에 Ansible 서버 및 노드들을 생성
앤서블 서버는 cpu 2개 / ram 4G
앤서블 노드는 cpu 2개 / ram 2G
앤서블이 노드 생성 시 설치되도록 구성
이후 자동으로 앤서블이 사용가능하도록 구성(키 복사는 수동으로 허용)
IP는 앤서블 서버에 192.168.111.10, 나머지 노드들에는 192.168.111.11~13을 부여하고 원격 접속용 포트는 30000번대로 구성
이후 앤서블 서버에서 나머지 노드들에게 앤서블을 통해 다음 작업을 수행
nextcloud를 자동으로 설치하여 앤서블 노드들에게 웹 브라우저 접속 시 설치 화면이 나오도록 구성