Skip to main content

Command Palette

Search for a command to run...

Ansible With Remote Server And Different Operating System..!!

Published
2 min read
Ansible With Remote Server And Different Operating System..!!

  • Debian Use For UBUNTU
  • RedHat Use For Amazon Linux

Task :- Install Lemp Stack In Two Different Os Remote Server

Steps :-

  • First Create one Ubuntu Server And Amazon Linux Server
  • Go Your Ansible Server Create Inventory File For Two Remote Server
nano myhost.ini
  • Add In Your Remote Server Ip In Your Inventory File

  • Code For Inventory File

[webserver]
13.233.3.137 ansible_ssh_user='ubuntu' ansible_private_key_file="kubernet.pem"
13.203.103.187 ansible_ssh-user='ec2-user' ansible_private_key_file="kubernet.pem"
  • Create Playbook For Lemp Stack
nano Diff-Os.yml
  • Code For PlayBook
- name: myplay1
  hosts: webserver
  become: true
  tasks:
   - name: update package manager in Ubuntu
     shell: apt update
     when: ansible_os_family=="Debian"
   - name: update package manager in A. Linux
     dnf:
      name: '*'
      state: latest
     when: ansible_os_family=="RedHat"
   - name: install LEMP on ubuntu server
     apt:
      name: "{{ item }}"
      state: present
     when: ansible_os_family=="Debian"
     with_items:
      - nginx
      - php
      - php8.3-fpm
      - mariadb-server
   - name: install LEMP on A.Linux server
     dnf:
      name: "{{ item }}"
      state: present
     when: ansible_os_family=="RedHat"
     with_items:
      - nginx
      - php
      - mariadb105-server
   - name: start all service in ubuntu server
     service:
      name: "{{ item }}"
      state: started
     when: ansible_os_family=="Debian"
     with_items:
      - nginx
      - php8.3-fpm
      - mariadb
   - name: start all service in A.Linux server
     service:
      name: "{{ item }}"
      state: started
     when: ansible_os_family=="RedHat"
     with_items:
      - nginx
      - php-fpm
      - mariadb
   - name: restart all service im ubuntu server
     service:
      name: "{{ item }}"
      state: restarted
     when: ansible_os_family=="Debian"
     with_items:
      - nginx
      - php8.3-fpm
      - mariadb
   - name: restart all service in A.linux server
     service:
      name: "{{ item }}"
      state: restarted
     when: ansible_os_family=="RedHat"
     with_items:
      - nginx
      - php-fpm
      - mariadb
  • Run Your PlayBook Using Inventory File
ansible-playbook -i myhost.ini Diff-Os.yml