Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

클라우드 엔지니어 꿈나무

Ansible 을 이용한 Apache + Wordpress + Mysql-server 설치 본문

Linux

Ansible 을 이용한 Apache + Wordpress + Mysql-server 설치

새싹싹이 2023. 9. 3. 23:51

Ansible을 이용하여 하기와 같이 구성

 

node 1 & 2 wordpress 설치

---
- name: install wordpress
  hosts:
   - was
   - web
  gather_facts: false
  ignore_errors: true
  tasks:

   - name: install mysql
     dnf:
      name: "{{ item }}"
      state: latest
     loop:
       - php
       - php-gd
       - php-cli
       - php-common
       - php-mysqlnd
       - php-opcache
       - php-curl
       - httpd
       - tar

   - name: wget
     get_url:
       url: https://ko.wordpress.org/wordpress-5.7.8-ko_KR.tar.gz
       dest: ./

   - name: unarchive wordpress
     unarchive:
       src: ./wordpress-5.7.8-ko_KR.tar.gz
       dest: ./
       remote_src: yes

   - name: copy directories
     copy:
       src: "{{ item.src }}"
       dest: "{{ item.dest }}"
       remote_src: yes
     loop:

       - {src: './wordpress/', dest: '/var/www/html/'}
       - {src: '/var/www/html/wp-config-sample.php', dest: '/var/www/html/wp-config.php'}


   - name: change html to php
     replace:
       path: /etc/httpd/conf/httpd.conf
       regexp: DirecroyIndex index.html
       replace: DirectoryIndex index.php

   - name: change sample to php
     replace:
       path: /var/www/html/wp-config.php
       regexp: "{{ item.src }}"
       replace: "{{ item.dest }}"
     loop:
       - {src: "database_name_here",dest: "wordpress"}
       - {src: "username_here", dest: "root"}
       - {src: "password_here", dest: "It12345!"}
       - {src: "localhost", dest: "10.0.0.14"}

   - name: httpd start
     systemd:
       name: httpd
       state: started

   - name: set firewall
     firewalld:
       port: 80/tcp
       permanent: yes
       immediate: yes
       state: enabled

 

 

 

node3 mysql-server 설치

---
- name: DB install
  hosts: db
  gather_facts: true
  ignore_errors: true
  tasks:

    - name: install packages
      dnf:
        name: mysql-server
        state: latest

    - name: start mysqld
      systemd:
         name: mysqld
         state: started

    - name: open firewall
      firewalld:
        port: 3306/tcp
        permanent: yes
        immediate: yes
        state: enabled

    - name: create user & database
      shell: |
        mysql -uroot -e "create user 'root'@'%' identified by 'It12345!';grant all privileges on *.* to 'root'@'%';create database wordpress;"

 

node 1 & 2 wordpress 제거

---
- name: remove wordpress & php
  hosts: 
    - web
    - was
  gather_facts: true
  ignore_errors: true
  tasks:

  - name: remove installation
      - wget
      - httpd
      - tar
      - php
      - php-common
      - php-gd
      - php-mysqlnd
      - php-curl
      - php-opcache
    dnf:
      state: absent

  - name: delete mysql dir & httpd dir
    file:
      path: "{{ item }}"
      state: absent
    loop:
      - /root/wordpress
      - /root/wordpress-5.7.8-ko_KR.tar.gz
      - /etc/httpd
      - /var/www/html

  - name: close firewall
    firewalld:
      port: 80/tcp
      state: disabled

 

node 3 my-sql server 제거

---
- name: remove mysql-server
  hosts: db
  gather_facts: true
  tasks:
    - name: delete mysql data
      shell: |
        mysql -uroot -e "drop database wordpress;revoke drop on *.* from 'root'@'%';flush privileges;drop user 'root'@'%'"


    - name: remove installation
      dnf:
        name: my-sqld
        state: absent

    - name: shut firewall
      firewalld:
        port: 3306/tcp
        state: disabled

'Linux' 카테고리의 다른 글

VMware Centos7 설치  (0) 2023.09.29
Ncloud Server 생성 및 Xshell 연결  (0) 2023.09.04
loadbalancer + wordpress + sqlnd-server 설치 -Rocky9  (0) 2023.09.02
LoadBalancer Haproxy - Rocky9  (0) 2023.09.02
SSH Ansible - Rocky9  (0) 2023.09.01