Version 11 (modified by 2 years ago) ( diff ) | ,
---|
Ansible Lab
In this lab, you will install and use Ansible to install MySQL/MariaDB and create database remotely.
Requirements:
Participants are requested to have a computer with Windows 8/10/11 (8GB RAM, 25GB free disk space) with Virtualbox (version 6 or higher) hypervisor and PuTTY installed.
In Virtualbox, 'Extension pack' should be installed.
A wired internet connection is preferred.
Virtual Machine (VM) Setup
Download VM from the following Link.
https://docs.learn.ac.lk/index.php/s/YcojJ2544b40Zw4
Import the VM to Virtualbox.
Username and Password: docker
May have to create Virtualbox Host-Only Network Adapter
File > Host Network Manager > Create
Test internet connectivity.
Login using PuTTY.
Setup Nodes
In control node
Login as root to the node and install Ansible
apt install ansible
In each managed node
Login as root to the node and install Ansible
apt install python3.10
Setup Passwordless SSH
In each node
Login as normal user.
ssh user > ssh-keygen -t rsa
Continue by entering the prompts.
In control node
cat /home/ubuntu/.ssh/id_rsa.pub
In managed node
Copy the ssh keys generated on the master node and save it in the authorized_keys file on both worker nodes.
nano /home/node/.ssh/authorized_keys
Create the Playbook - In control node
nano <playbook name>.yml
- name: setup mysql become: yes hosts: Dbservers vars: - user: test - password: M@#567uers - db: testdb tasks: - name: installing mysql and dependencies package: name: "{{item}}" state: present update_cache: yes loop: - mysql-server - mysql-client - python3-mysqldb - libmysqlclient-dev become: yes - name: start and enable mysql service service: name: mysql state: started enabled: yes - name: creating mysql user mysql_user: name: "{{user}}" password: "{{password}}" priv: '*.*:ALL' host: '%' state: present - name: creating db mysql_db: name: "{{db}}" state: present handlers: - name: restart mysql service: name: mysql state: restarted
Run the Playbook - In control node
ansible-playbook <playbook name>.yml -e
Attachments (1)
- internal net.png (31.0 KB ) - added by 2 years ago.
Download all attachments as: .zip