Monday, November 2, 2026
Explore Technology
Connect knowledge - Elevate skills
Automation 3 min read

[Ansible] Hướng dẫn cài đặt WordPress trên nhiều host

admin Th9 21, 2021 0 comments
[Ansible] Hướng dẫn cài đặt WordPress trên nhiều host

Step 1 – Cài đặt ansible

Xem hướng dẫn cài đặt : Hướng dẫn cài đặt ansile Server Client

Step 2 – Tải file ansible-wordpress về

Link tải: ansile-wordpress.yml

hoặc copy từ nội dung bên dưới:

---
  - name: Setup webserver
    hosts: client
    become: true
    tasks:
    - name: Yum update
      shell: yum update -y
    - name: Install ntpdate
      shell: yum install ntpdate net-tools -y
    - name: Install the latest version of apache
      yum:
        name: httpd
        state: latest
    - name: Disable Selinux
      ansible.posix.selinux:
        state: disabled 
    - name: Open Port http
      ansible.posix.firewalld:
        service: http
        permanent: yes
        state: enabled
    - name: Open port https     
      ansible.posix.firewalld:
        service: https
        permanent: yes
        state: enabled
    - name: Install Epel-release
      package:
        name: epel-release
        state: latest
    - name: Install yum untils
      shell: yum install yum-utils -y
    - name: Download repo PHP
      shell: yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    - name: Disable PHP 5.4
      shell: yum-config-manager --disable remi-php54
    - name: Enable PHP 7.3
      shell: yum-config-manager --enable remi-php73
    - name: Install php-gd
      shell: yum -y install php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl
    - name: Install phpmyadmin
      shell: yum -y install phpmyadmin
    - name: Yum Wget
      yum:
        name: wget
        state: latest
    - name: Download Repo Mariadb
      get_url:
        url: https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
        dest: /root
        mode: +x
    - name: cd in folder root
      ansible.builtin.command:
        cmd: cd /root
    - name: Install mariadb from repo
      ansible.builtin.command:
        cmd: ./mariadb_repo_setup
    - name: Install mariadb
      ansible.builtin.command:
        cmd: yum install MariaDB-server -y
        warn: false
    - name: Start and enable Mariadb
      service:
        name: mariadb
        enabled: true
        state: started
    - name : Start and  enable httpd
      service:
        name: httpd
        state: started
        enabled: true
    - name: Install MYSQL-Python 2.7
      ansible.builtin.command:
        cmd: yum install MySQL-python -y
    - name: Create wordpress DB
      community.mysql.mysql_db:
        name: wpdb
        state: present
    - name: Remove all anonymous user
      community.mysql.mysql_user:
        name: ''
        host_all: yes
        state: absent
    - name: Create database user with all database privileges
      community.mysql.mysql_user:
        name: wpuser
        password: wp123456
        priv: '*.*:ALL'
        state: present
    - name: Download source WordPress
      get_url: 
        url: https://wordpress.org/wordpress-5.7.2.tar.gz
        dest: /root
    - name: Extract source WP
      unarchive:
        src: /root/wordpress-5.7.2.tar.gz
        dest: /root/
        remote_src: yes
    - name: Move source to /var/www/html
      shell: mv /root/wordpress/* /var/www/html/
    - name: Set user group
      shell: chown -R apache:apache /var/www/html/*
    - name: Backup file config
      shell: cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
    - name: Config DB name
      replace:
        path: /var/www/html/wp-config.php
        regexp: 'database_name_here'
        replace: 'wpdb'
    - name: Config user db
      replace:
        path: /var/www/html/wp-config.php
        regexp: 'username_here'
        replace: 'wpuser'
    - name: Connfig Password DB
      replace:
        path: /var/www/html/wp-config.php
        regexp: 'password_here'
        replace: 'wp123456'
    - name: Restart Apache
      service:
        name: httpd
        state: restarted
    - name: Restart firewalld
      shell: systemctl restart firewalld

Step 3 – Chạy lệnh ansible Playbook

Bash / Shell

[root@gitlab ~]# ansible-playbook -i ansible-wordpress.yml

Sau khi lệnh chạy xong thì tiến hành vào IP setup bước còn lại

admin

Technical author & IT enthusiast at SystemZoneVN (systemzonevn.top).

Latest Tech Posts

Fresh updates from systemzonevn.top
All Posts
Làm Chủ Docker Logs Linux

Làm Chủ Docker Logs

Chào các bạn lập trình viên và quản trị hệ thống! Khi làm việc với…

9 min read Th10 01, 2026
0 0 đánh giá
Đánh giá bài viết
Theo dõi
Thông báo của
guest
0 Góp ý
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất

Fast Updates

Latest & breaking tech news

Quality Content

Verified & carefully curated

Community

Learn, share and grow together

Always Connected

Empowering developers & tech enthusiasts

0
Rất thích suy nghĩ của bạn, hãy bình luận.x