Rabu, 10 Juli 2024

ANSIBLE-reset password

 

Configure Multiple Servers with Ansible

https://news.descreated.com/teknologi/1808/konfigurasi-banyak-server-dengan-ansible/202208031931/
  • SHARE

Ansible  is an infrastructure as code tool that functions as configuration management. Ansible can configure multiple servers at the same time automatically.

Ways of working

Hosts on which Ansible is installed (Control Nodes) must be able to connect to the hosts to be configured (Managed Nodes) via the SSH protocol. Managed Nodes do not need to install agents or other additional applications, just activate SSH.

The list of Managed Nodes is stored in the Inventory file by writing down the IP or hostname.

Configuration commands (Tasks) are commands that are specific to just one command (one task = one command) defined in the Playbook file. For example, if there is an update and an install, it means there are 2 tasks. Commands that can be run in tasks are called  Modules  or Task Plugins, for example there are for packaging, network, and database.

0. Tutorial Environment

Environment used in this tutorial:

  • Control Node: Ubuntu 20.04
  • Managed Nodes: 2x VPS Ubuntu 20.04
    • Webserver host 178.128.55.175
    • Database host 165.22.102.165
  • Ansible v2.12.6

1. Install SSH Key

Install an SSH key so that Ansible can communicate with Managed Nodes via SSH by authenticating using the key.

Create an SSH key on the Control Node.

 

For example, the key is stored with the name ansible.

 

Sending keys to the webserver host and database, using the root user.

 

Testing SSH connections.

 

Install Ansible

Install Ansible on Ubuntu.

 

Installing Ansible on other operating systems read at  docs.ansible.com

Inventory Settings

Ansible provides a default Inventory file in  /etc/ansible/hosts , but you can also create your own custom Inventory files.

Create a folder to store Ansible project files.

 

Create an Inventory file, for example, give it the name inventory.

 

Fill inventory.

 

  • Setting the user and key used by Ansible.
  • Create [webserver] and [database] host groups. If there are other servers you want to include, just add the IP in the desired group.

Check inventory by displaying all existing hosts.

 

The result.

 

Testing Ansible connection to hosts.

 

The result.

 

Playbooks

Create a Playbook file, for example named playbook.yml.

 

Fill in the playbook.yml file.

 

Command to be executed:

  • Update apt cache on all hosts
  • Install Nginx and PHP on the hosted webserver
  • Install MariaDB on the host database, create a database, user, and set a root password

Running playbooks.

 

The result.

 

Testing

Testing the results of the Ansible configuration, checking Nginx and PHP on the webserver host and browsing http://IP-Server.

 

Checking the database and database users on the host database.

Good luck ?

Tidak ada komentar:

Posting Komentar