Ansible Quick Start Guide
上QQ阅读APP看书,第一时间看更新

Source GitHub or tarball installation

Being able to build up Ansible from its source is helpful for users in an uncommon environment, or for those who have some special requirements, such as setting up Ansible without the need of a package manager or being limited to the latest stable version of Ansible. Using the development version of Ansible (or beta) always puts its user at risk of having unstable modules and plugins, but also allows for early access to future modules.

To acquire Ansible's source package, we can use two different methods: downloading the .tar file, or cloning the GitHub repository of the project. The Ansible project source files are located in its releases page (releases.ansible.com/ansible/), and the GitHub source can be cloned from the official GitHub project (github.com/ansible/ansible).

To download the tarball file, use your favorite file fetching tool (such as curl, wget, or axel):

wget -c https://releases.ansible.com/ansible/ansible-2.6.0rc3.tar.gz

We then need to un-archive the tarball:

tar -xzvf  ./ansible-2.6.0rc3.tar.gz

Alternatively, we can use Git to clone the GitHub project locally. We need to make sure that Git is installed on the system, and then we can start cloning. This process is shown for a number of systems in the following snippets.

The following command line shows how to install git on a Linux from the Red Hat family:

sudo yum install -y git

The following command line shows how to install git on a Linux from the Debian family:

sudo apt install -y git

The following command line shows how to install git on Mac OS X:

brew install git

On all the systems, to clone the Ansible GitHub project:

git clone https://github.com/ansible/ansible.git --recursive

We then need to start building Ansible, either by getting the tarball or the source from GitHub:

cd ./ansible*

To make sure that all the requirements for building Ansible are met easily, we will be using Python PyPI. The PyPI installation on multiple systems is covered in the preceding section. For this section, we will use easy_install, which only requires you to install a version of Python on the system:

sudo easy_install pip

We now install the Python requirements:

sudo pip install -r ./requirements.txt

We need to set up the environment as follows to be able to use Ansible:

source ./hacking/env-setup

Updating Ansible when using the GitHub project can be trickier. We need to pull the project and its submodules as follows:

git pull --rebase
git submodule update --init --recursive

Every time those commands are executed, we need to make sure that the environment is properly set up:

echo "export ANSIBLE_HOSTS=/etc/ansible/hosts" >> ~/.bashrc
echo "source ~/ansible/hacking/env-setup" >> ~/.bashrc

The location of the environmental source can change whenever the Ansible source is located. The Ansible inventory (usually located in /etc/ansible/hosts) and its configuration file (usually located in /etc/ansible/ansible.cfgcan also be changed to accommodate permission restrictions or provide Ansible users with easier access to enable modifications or restrict them. This will be covered in more detail later in this chapter.