Deploying on remote servers with Ansible
If we manage several remote servers, running commands on them manually can be frustrating and time consuming. Ansible allows to run commands on a whole group of servers.
This page shows some examples of ansible-playbook invocations. We'll see how to deploy roles or parts of them to remote servers. Then we'll see how to run commands on remote hosts, possibly to get information from them. Make sure to read Ansible Overview first, to understand Ansible general concepts.
Pinging Remote Servers
Let's start with the simplest example: we just want our local Ansible to ping remote servers to see if they are reachable. Here's how to do it:
ansible -i production-mariadb all -m ping
Before proceeding with more useful examples, let's discuss this syntax.
- ansible is the executable we can call to run a command from remote servers.
- -i production-mariadb means that the servers must be read from an inventory called production-mariadb.
- all means that the command must be executed against all servers from the above inventory.
- -m ping specifies that we want to run the ping module. This is not the ping Linux command. It tells us if Ansible is able to connect a remote server and run a simple commands on them.
To run ping on a specific group or host, we can just replace "all" with a group name or host name from the inventory:
ansible -i production-mariadb main_cluster -m ping
Running Commands on Remote Servers
Applying Roles to Remote Servers
Content initially contributed by Vettabase Ltd.