Ansible With Remote Server..!!
How To Set Remote Server And How To Do Changes In Remote Server With Ansible ?
Get the remote server's key pair from your Ansible server And Give Permission +x .
scp -i .\Downloads\kuberneet.pem .\Downloads\kuberneet.pem ubuntu@13.201.229.11:.
sudo chmod 400 kuberneet.pem
After Add Your Remote Server Private/public Ip In Our Inventory File
- Code For Inventory File
[webserver]
172.31.9.64 ansible_ssh_user='ubuntu' ansible_private_key_file="kubernet.pem"
After Adeed This Code In your inventory file Write Your PlayBook And Run
Code For PlayBook
nano Lemp-Book.yml
- name: install LEMP on localhost
hosts: webserver
become: true
connection: local
tasks:
- name: install nginx
apt:
name: nginx
state: present
- name: start nginx service
service:
name: nginx
state: started
- name: install php
apt:
name: php
state: present
- name: update apt
shell: 'apt update'
- name: install php8.3-fpm
apt:
name: php8.3-fpm
state: present
- name: start php-fpm service
service:
name: php8.3-fpm
state: started
- name: install mysql
apt:
name: mariadb-server
state: present
- name: start mysql service
service:
name: mariadb
state: started
- name: restart nginx service
service:
name: nginx
state: restarted
- name: restart php-fpm service
service:
name: php8.3-fpm
state: restarted
- name: restart mysql service
service:
name: mariadb
state: restarted
- After That Run Your Ansible PlayBook Using Inventory File
ansible-playbook -i myhost.ini Lemp-Book.yml (Here playbook Name)