# Automation Installation LAMP dan CMS WordPress dengan Menggunakan Ansible

<figure><img src="https://nos.wjv-1.neo.id/cdn.medusa.my.id/Automation%20Bot.png" alt=""><figcaption></figcaption></figure>

## Introduction

Berikut ini adalah tulisan mengenai bagaimana cara mengotomasikan instalasi dan konfigurasi server CentOS dengan spesifikasi paket perangkat lunak LAMP (Linux, Apache, MariaDB dan PHP) serta CMS WordPress dan berikut kebutuhan yang perlu kita siapkan sebelumnya, antara lain:

## Requirements

* [**Ansible**](https://docs.ansible.com/ansible/2.9/installation_guide/intro_installation.html#installing-ansible-on-rhel-centos-or-fedora).
* [**Git**](https://git-scm.com/downloads).

## Installation

### Install Paket Software Git & Ansible

Pertama, kita perlu meng-install Git dan Ansible terlebih dahulu di master dan berikut perintah yang perlu dijalankan:

{% code overflow="wrap" lineNumbers="true" %}

```bash
yum install epel-release -y
yum update -y
yum install git ansible -y
```

{% endcode %}

### Cloning Public Repository Git

Setelah itu kita perlu melakukan cloning public repository Git untuk Ansible Playbook berikut:

{% code overflow="wrap" lineNumbers="true" %}

```bash
cd /opt
git clone https://github.com/madfxr/ansible-httpd-wordpress-mariadb-remotely.git
```

{% endcode %}

### Melihat Versi dari Ansible

Setelah Ansible sudah berhasil ter-install di master, kemudian jalankan perintah berikut untuk melihat versi yang ter-install di master:

{% code overflow="wrap" lineNumbers="true" %}

```bash
ansible --version
```

{% endcode %}

### Generate SSH Key

Langkah selanjutnya yakni kita perlu melakukan generate SSH Key, hal ini dilakukan untuk generate Private Key dan Public Key yang akan digunakan sebagai autentikasi komunikasi antara dua host atau lebih, dan berikut perintahnya:

{% code overflow="wrap" lineNumbers="true" %}

```bash
ssh-keygen -t rsa -b 4096
```

{% endcode %}

{% hint style="info" %}

```markdown
ssh-keygen = OpenSSH authentication key utility
-t rsa = Specifies the type of key to create is RSA
-b 4096 = Specifies the number of bits in the key to create is 4096 bits
```

{% endhint %}

### Konfigurasi Ansible Host

Lakukan perubahan pada host sesuai dengan kebutuhan deployment yang kita miliki dengan menjalankan perintah berikut:

{% code overflow="wrap" lineNumbers="true" %}

```bash
vi /etc/ansible/hosts
```

{% endcode %}

Dan tambahkan baris kode berikut ini:

{% hint style="warning" %}
{% code title="/etc/ansible/hosts" %}

```markdown
[websrv]
192.168.1.1

[dbsrv]
192.168.1.2
```

{% endcode %}
{% endhint %}

### Autentikasi Akses SSH

Proses selanjutnya adalah mengotentikasi login pada host **192.168.1.1** dan **192.168.1.2** dan beirkut perintahnya:

{% code overflow="wrap" lineNumbers="true" %}

```bash
ssh-copy-id root@192.168.1.1
ssh-copy-id root@192.168.1.2
```

{% endcode %}

### Verifikasi Host

Untuk melakukan pemeriksaan koneksi pada host yang ditambahkan sebelumnya, jalankan perintah berikut:

{% code overflow="wrap" lineNumbers="true" %}

```bash
ansible -m ping websrv
ansible -m ping dbsrv
```

{% endcode %}

### Install Paket Software LAMP

Untuk meng-install paket dan mengonfigurasi LAMP (Linux, Apache, MariaDB dan PHP) serta CMS WordPress, jalankan perintah berikut:

{% code title="Install Package" overflow="wrap" lineNumbers="true" %}

```bash
ansible-playbook /opt/ansible-httpd-wordpress-mariadb-remotely/roles/install-httpd-wordpress-mariadb-remotely.yml
```

{% endcode %}

### Remove Paket Software LAMP

Untuk meng-remove paket dan mengonfigurasi LAMP (Linux, Apache, MariaDB dan PHP) serta CMS WordPress, jalankan perintah berikut:

{% code title="Remove Package" overflow="wrap" lineNumbers="true" %}

```bash
ansible-playbook /opt/ansible-httpd-wordpress-mariadb-remotely/roles/erase-httpd-wordpress-mariadb-remotely.yml
```

{% endcode %}

### Install Paket Software LAMP & Restore Database

Untuk meng-install paket dan mengonfigurasi LAMP (Linux, Apache, MariaDB dan PHP) serta CMS WordPress, juga melakukan restorasi database beserta konten website, jalankan perintah berikut:

{% code title="Install Package, Restore Database & Content" overflow="wrap" lineNumbers="true" %}

```bash
ansible-playbook /opt/ansible-httpd-wordpress-mariadb-remotely/roles/restore-httpd-wordpress-mariadb-remotely.yml
```

{% endcode %}

## Configuration

### File Konfigurasi Ansible

Untuk membuat perubahan pada file konfigurasi Ansible, dapat mengubah file konfigurasi berikut:

{% hint style="info" %}

```bash
/etc/ansible/hosts
/opt/ansible-httpd-wordpress-mariadb-remotely/.my.cnf
/opt/ansible-httpd-wordpress-mariadb-remotely/wp-config-sample.php
/opt/ansible-httpd-wordpress-mariadb-remotely/roles/erase-httpd-wordpress-mariadb-remotely.yml
/opt/ansible-httpd-wordpress-mariadb-remotely/roles/install-httpd-wordpress-mariadb-remotely.yml
/opt/ansible-httpd-wordpress-mariadb-remotely/roles/wordpress/tasks/main.yml
/opt/ansible-httpd-wordpress-mariadb-remotely/roles/httpd/defaults/main.yml
/opt/ansible-httpd-wordpress-mariadb-remotely/roles/mariadb/tasks/main.yml
/opt/ansible-httpd-wordpress-mariadb-remotely/roles/wordpress/tasks/restore.yml
/opt/ansible-httpd-wordpress-mariadb-remotely/roles/mariadb/tasks/restore.yml
```

{% endhint %}

> **Catatan:**
>
> * Ansible Playbook diatas hanya dicoba di sistem operasi CentOS 7 x86\_64 saja.
> * Jika menggunakan sistem operasi lain, jangan lupa untuk melakukan perubahan pada role yang sudah ada.

Demikian sedikit pengetahuan dan pengalaman yang dapat saya bagikan, semoga apa yang telah saya sampaikan dapat bermanfaat bagi kita semua.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.madfxr.my.id/documentation/categories/devops/automation-installation-lamp-dan-cms-wordpress-dengan-menggunakan-ansible.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
