Ansible

From TheBestLinux.com
Jump to navigationJump to search

Ansible is a very useful tool for managing large numbers, or even small numbers, of servers both remotely and locally using SSH(Secure Shell) and the Python language.

To start with, Ansible needs it's own hosts file which it uses as a list of servers it manages. Servers can be grouped in sections starting with a descriptive header enclosed in square brackets, or just indivitual hostnames or and/or IP addresses. Here is a basic example showing just one server configured, my main local DNS server:

# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups
#
#   Jamie Created:
ns1.dawgland.com

# Ex 1: Ungrouped hosts, specify before any group headers.



Here is an example of how to use Ansible to upgrade a remote host:

ansible ns1.dawgland.com -m dnf -a "name=* state=latest" -b
ns1.dawgland.com | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Installed: oniguruma5php-6.9.7.1-1.el8.remi.x86_64",
        "Removed: oniguruma5php-6.9.6-1.el8.remi.x86_64"
    ]
}