new template

Photo of author

By admin

Certainly! Here’s an example of how to use Ansible to install SSH on remote servers:

  1. Create an inventory file named hosts with the IP addresses or hostnames of your target servers:
[my_servers]
server1 ansible_host=192.168.1.100
server2 ansible_host=192.168.1.101
  1. Create a playbook file named install_ssh.yml with the following content:
---
- name: Install SSH
  hosts: my_servers
  become: true

  tasks:
    - name: Install OpenSSH server
      apt:
        name: openssh-server
        state: present
      when: ansible_distribution == "Ubuntu"  # Adjust for other distributions

    - name: Start SSH service
      service:
        name: ssh
        state: started
        enabled: yes
  1. Save the playbook file and run the following command to execute the playbook:
$ ansible-playbook -i hosts install_ssh.yml

This playbook uses Ansible to install the OpenSSH server package and start the SSH service on the remote servers specified in the inventory file. It assumes you are targeting Ubuntu servers, but you can modify the when condition to match the distribution you are using.

Make sure you have Ansible installed on the machine from where you are running the playbook, and ensure you have SSH access to the target servers using password or key-based authentication.

Adjust the inventory file and playbook content according to your specific server configuration and requirements.

Leave a Comment