Ansible - Installation - Version 2.7

> Infrastructure as code > Ansible

1 - About

2 - Requirement

2.1 - Control Machine

Ansible can be run from any machine with Python 2 (version 2.7) or Python 3 (versions 3.5 and higher) installed. Windows isn’t supported for the control machine.

2.2 - Managed Node

On the managed nodes, you need a way to communicate, which is normally ssh. By default this uses sftp. If that’s not available, you can switch to scp in ansible.cfg. You also need Python 2 (version 2.6 or later) or Python 3 (version 3.5 or later).

If you have SELinux enabled on remote nodes, you will also want to install libselinux-python on them before using any copy/file/template related functions in Ansible. You can use the yum module or dnf module in Ansible to install this package on remote systems that do not have it.

Advertising

3 - Steps

  • using the OS package manager for Red Hat Enterprise Linux (TM), CentOS, Fedora, Debian, or Ubuntu, we recommend
  • using Pip

3.1 - Python installation

Ansible’s “raw” module don’t even need Python installed. So technically, you can use Ansible to install a compatible version of Python using the raw module, which then allows you to use everything else.

Example:

ansible host-pattern --become -m raw -a "yum install -y python2"

3.2 - Interpreter

By default, Ansible uses the python interpreter located at /usr/bin/python to run its modules.

If it's not the case, you can set the ansible_python_interpreter inventory variable to point at your interpreter

3.3 - Azure

See Install Ansible

  • Ubuntu
## Install pre-requisite packages
sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev python-pip
 
## Install Ansible and Azure SDKs via pip
sudo pip install ansible[azure]
  • Centos
sudo yum check-update; sudo yum install -y gcc libffi-devel python-devel openssl-devel epel-release
sudo yum install -y python-pip python-wheel
Advertising

3.4 - Test if Ansible is installed

From Ansible task …?

- name: Install ansible
  yum: pkg=ansible state=installed

4 - Verification

pip show ansible
---
Metadata-Version: 1.1
Name: ansible
Version: 2.7.1
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: [email protected]
License: GPLv3+
Location: /usr/lib/python2.7/dist-packages
Requires:
Classifiers:
  Development Status :: 5 - Production/Stable
  Environment :: Console
  Intended Audience :: Developers
  Intended Audience :: Information Technology
  Intended Audience :: System Administrators
  License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
  Natural Language :: English
  Operating System :: POSIX
  Programming Language :: Python :: 2
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3
  Programming Language :: Python :: 3.5
  Programming Language :: Python :: 3.6
  Programming Language :: Python :: 3.7
  Topic :: System :: Installation/Setup
  Topic :: System :: Systems Administration
  Topic :: Utilities

5 - Docker

6 - Support

6.1 - "module_stdout": "/bin/sh: /usr/bin/python: No such file or directory\r\n"

Verify your interpreter