Ansible

From Gentoo Wiki
Jump to: navigation, search
This article is a stub. You can help by expanding it.
Resources

Ansible is a configuration management system written in Python. It can be used for automating machine deployments.

Installation

USE flags

USE flags for app-admin/ansible Model-driven deployment, config management, and command execution framework

test Workaround to pull in packages needed to run with FEATURES=test. Portage-2.1.2 handles this internally, so don't set it in make.conf/package.use anymore global

Emerge

Install app-admin/ansible:

root #emerge --ask app-admin/ansible

Configuration

The app-admin/ansible-1.9.6 ebuild will not generate the basic configuration. The default inventory file is named hosts should be in the /etc/ansible directory

root #mkdir /etc/ansible
root #nano /etc/ansible/hosts

This file contains the managed computers organized in groups.

FILE /etc/ansible/hostsSample inventory file
[all:vars]
# IMPORTANT
ansible_python_interpreter=/usr/bin/python2.7

[servers]
myserver01
myserver02
myserver03

[workstations]
evapc ansible_ssh_user=myuser ansible_ssh_port=9000
joepc ansible_ssh_user=myuser
mypc ansible_ssh_user=myuser ansible_connection=local

With ansible_ssh_user= and ansible_ssh_port= remote users and ssh ports can be specified per hosts. From 2.0 version they are deprecated, use ansible_user and ansible_port instead. The first two lines are crucial to explicitly set Ansible's python interpreter for all hosts, Ansible only works with python 2.7, and even is the python_targets_python2_7 flag is set, it will use your system python by default. It is unnecessary if your system python is 2.7, but still recommended to avoid unexpected failure if you change it.

FILE /etc/ansible/ansible.cfgDefault configuration
[defaults]
# Default remote user
remote_user = root
# SSH timeout in seconds
timeout = 10

Show current ansible configuration

user $ansible-config view

Roles for Gentoo

Over 40 roles specifically for Gentoo can be found in the https://github.com/gentoo-ansible project.

Usage

Check if ansible can manage remote machine with given user:

root #ansible evapc -u myuser -m ping

Get info from remote machine, what can be used later in playbooks:

root #ansible evapc -u myuser -m setup

Run emerge --sync on evapc under myuser via sudo:

root #ansible evapc -s -u myuser -m command -a "emerge --sync"
Option Description
-u Specifies the user, if absent ansible will search in your inventory file for default user associated to the given host, if not any it will use the default specified in the /etc/ansible/ansible.cfg file, if there is no such an entry it will use the current username.
-m Specifies the module to be invoked.
-a Specifies the arguments to passed to the module.

The ansible-doc command can be used to read module documentation. For example, to list available modules:

user $ansible-doc -l

To print out info about the ping module:

user $ansible-doc ping