How to install apps remotely with Ansible

Just one pretty hand trick up Ansible’s sleeve is the ability to put in apps on remote servers. Jack Wallen displays you how to make this work.

Picture: TechRepublic/Jack Wallen

Ansible is a person of people resources that, as soon as you commence applying it, you can expect to wonder how you managed without–it is that versatile and useful. From within a one playbook, you can deal with program provisioning, configure remote equipment, and deploy purposes to remote methods in your information center.

I’ve currently walked you by the generation of playbooks, deploying a container, and how to operate a command with Ansible. This time about, I am going to show you how to set up a piece of computer software on a remote server, with very little but an Ansible playbook consisting of nine traces.

SEE: Using the services of kit: Databases administrator (TechRepublic Top quality)

What you are going to will need

How to copy the SSH vital to the distant server

The initially matter we want to do is to copy our SSH vital to the distant server. For those that do not now know how to get the job done with SSH key authentication, see my put up: How to established up ssh vital authentication.

You need to already have an SSH crucial created. If not, just take care of that now. As soon as you have your vital, copy it to the server with the command:

ssh-duplicate-id Consumer@SERVER

The place Person is the username on the remote machine and SERVER is the distant machine’s IP handle. With the SSH critical copied, you happen to be ready to go.

How to configure the hosts

In advance of we make our playbook, let us configure the host. Say the new host will belong to a selection of databases servers. To do this, you may want to generate a new portion in the Ansible hosts file. Open that file for modifying with the command:

sudo nano /etcetera/ansible/hosts

Scroll to the base of that file and generate a new segment that appears to be like like this:

[db_servers]
SERVER ansible_user=Consumer

Where by SERVER is the IP address of the distant server and Consumer is the distant username. You are going to want to use the identical username which is connected with the SSH crucial you just copied. 

Preserve and close the file.

How to create the playbook

Due to the fact I’ll be setting up on a Ubuntu-based mostly distant server, I am going to title this playbook apt.yml. What I am going to demonstrate is a quite essential solitary application set up. 

This playbook will do the pursuing:

The playbook seems to be like this:

- hosts: db_servers
  duties:
    - identify: Ansible apt set up packages instance
      develop into: real
      become_user: root
      apt:
        identify: zip
        condition: current
        update_cache: true

Bear in mind, considering that this is a YAML file, the indentation ought to be dependable, normally it will fall short. At the time you have the file set up properly, save and close it.

If you ended up wanting to put in far more than one particular bundle, you’d have to modify the apt section of the playbook to reflect this modify:

apt:
    name:
    - zip
    - wget
    condition: present
    update_cache: real

Every single software would get its very own line.

How to run the playbook

Back at the terminal window, situation the command:

ansible-playbook apt.yml --check with-develop into-pass

You will 1st be asked for the sudo password, adopted by the SSH essential authentication password. When you’ve got properly authenticated in opposition to people two devices, the playbook will successfully run and the zip package deal will be put in on the remote device. Immediately after Ansible completes, you need to see okay=1 in the output, indicating the package deal was correctly installed. If you put in a number of deals, you’ll see okay=X (Where X is the selection of deals set up).

And that is how you can quickly deploy applications to your distant servers, from a single Ansible playbook. 

Also see

Fibo Quantum