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

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


USE flags

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


Install app-admin/ansible:

root #emerge --ask app-admin/ansible


The app-admin/ansible-1.9.6 ebuild will not generate the basic configuration. Ansible upstream provides an example configuration file that includes all options for convenience.

The default inventory file is named hosts. It should be created 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


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 the system's python by default. It is unnecessary if the system python is version 2.7, but still recommended to avoid unexpected failure if you change it.

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

To show current ansible configuration, issue:

user $ansible-config view

Roles for Gentoo

Over 40 roles specifically for Gentoo can be found in the project.


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