This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.
Please visit our production wiki at https://wiki.gentoo.org
Ansible
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
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. 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.
/etc/ansible/hosts
Sample 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 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.
/etc/ansible/ansible.cfg
Default configuration[defaults] # 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 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