Infrastructure at your Service

Daniel Westermann

Getting Ansible up and running on a SLES 12 SP1 host

Recently at a customer we had to setup Ansible on a SLES 12 SP1 host. In comparison to RedHat or Ubuntu based distributions there are some more steps to do as Ansible is not included in the standard SLES repositories. Here we go …

Start with the user, group, directories and permissions:

host:~ # groupadd ansible
host:~ # useradd -g ansible -m ansible
host:~ # passwd ansible
host:~ # mkdir /opt/ansible
host:~ # chown ansible:ansible /opt/ansible
host:~ # mkdir /etc/ansible
host:~ # chown ansible:ansible /etc/ansible
host:~ # touch /etc/ansible/hosts
host:~ # chown ansible:ansible /etc/ansible/hosts
host:~ # chmod 600 /etc/ansible/hosts

In our case we wanted to install Ansible directly from the git repository on github so we needed to install git:

host:~ # zypper install git

As pip was not available in the os repositories we had to install manually:

host:~ # cd /var/tmp
host:~ # export http_proxy=proxy:port    # if a proxy is used
host:~ # export https_proxy=proxy:port   # if a proxy is used
host:~ # wget https://bootstrap.pypa.io/get-pip.py
host:~ # python get-pip.py
host:~ # pip install paramiko PyYAML Jinja2 httplib2 six

Installing Ansible from here on is straight forward:

host:/var/tmp # su - ansible
[email protected]:~> cd /opt/ansible/
[email protected]:/opt/ansible> export http_proxy=webproxy.amag.car.web:8080
[email protected]:/opt/ansible> export https_proxy=webproxy.amag.car.web:8080
[email protected]:/opt/ansible> git config --global http.proxy $http_proxy
[email protected]:/opt/ansible> git config --global https.proxy $http_proxy
[email protected]:/opt/ansible>git clone https://github.com/ansible/ansible.git --recursive
[email protected]:/opt/ansible>cd ansible
[email protected]:/opt/ansible/ansible> git pull --rebase
Current branch devel is up to date.
[email protected]:/opt/ansible/ansible> [email protected]:/opt/ansible/ansible> git submodule update --init --recursive

Ansible provides a script which makes it easy to setup the environment:

[email protected]:/opt/ansible/ansible>cd ansible
[email protected]:/opt/ansible/ansible>. hacking/env-setup

This does the initial stuff required for running Ansible out of a git repository and does set all the environment variables. It is good idea to do this automatically once you login as ansible user:

[email protected]:/opt/ansible/ansible> echo ". /opt/ansible/ansible/hacking/env-setup -q" >> ~/.bash_profile

Now you can execute ansible without adjusting your environment or switching to the installation directory:

[email protected]:/opt/ansible/ansible> which ansible
/opt/ansible/ansible/bin/ansible
[email protected]:/opt/ansible/ansible> ansible --version
ansible 2.2.0 (devel 4cc4dc6793) last updated 2016/07/19 13:51:23 (GMT +200)
  lib/ansible/modules/core: (detached HEAD 7de287237f) last updated 2016/07/19 13:51:40 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 68ca157f3b) last updated 2016/07/19 13:51:53 (GMT +200)
  config file =

To test we can add the localhost to the Ansible inventory:

[email protected]:/opt/ansible/ansible> echo "127.0.0.1" >> /etc/ansible/hosts

… and then exchange the public ssh key of the ansible user:

[email protected]:~> ssh-keygen -t dsa
[email protected]:~> ssh-copy-id -i ~/.ssh/id_dsa.pub [email protected]

Do a functional test:

[email protected]:~>  ansible all -m ping
127.0.0.1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

… and your done. Happy deploying …

6 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Daniel Westermann
Daniel Westermann

Principal Consultant & Technology Leader Open Infrastructure