Ansible

From XennisWiki
Jump to: navigation, search

Ansible is a free software platform for configuring and managing computers. It combines multi-node software deployment, ad hoc task execution, and configuration management. It manages nodes over SSH or PowerShell and requires Python to be installed on them. Modules work over JSON and standard output and can be written in any programming language. The system uses YAML to express reusable descriptions of systems. (Wikipedia)

Installation

Further information: Ansible Documentation - Installation

Using pip
pip install ansible
Debian/Ubuntu (without pip)
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

Modules

Packages

Install Linux packages (apt)

Further information: apt module

name: Install java(7-jdk)
apt: pkg={{item}} state=installed
with_items:
  - openjdk-7-jdk
  - openjdk-7-jre-lib

Install Perl packages (cpanm)

Further information: cpanm module

name: Install perl dependencies
cpanm: name={{item}}
with_items:
  - Class::Struct
  - File::Basename

Install Python packages (pip)

Further information: pip module

name: Install Python dependencies
pip: name={{item}}
with_items:
  - subprocess32
  - requests

Files

Download files (get_url)

Further information: get_url module

name: Download example.pdf
get_url: url=https://example.org/example.pdf
        dest={{SAMPLE_PATH}}

Unpack archives (unarchive)

Download and extract a archive

- name: Download and extract archive
  unarchive:
    src: https://example.org/example.zip
    dest: /tmp
    remote_src: True

Execute commands (command)

Further information: command module

name: Maven install
command: mvn clean install
         chdir={{SAMPLE_PATH}}

Clone repositories (git)

Further information: git module

name: Clone example repository
git: repo=https://github.com/user/example.git
     dest={{SAMPLE_PATH}}

Tips

Install modules from Ansible Galaxy

ansible-galaxy install username.role_name

Usage with Vagrant

see Vagrant

Simulate run and show changes

Use --check --diff (or -C -D).

See also

External links