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 ansible@host:~> cd /opt/ansible/ ansible@host:/opt/ansible> export http_proxy=webproxy.amag.car.web:8080 ansible@host:/opt/ansible> export https_proxy=webproxy.amag.car.web:8080 ansible@host:/opt/ansible> git config --global http.proxy $http_proxy ansible@host:/opt/ansible> git config --global https.proxy $http_proxy ansible@host:/opt/ansible>git clone https://github.com/ansible/ansible.git --recursive ansible@host:/opt/ansible>cd ansible ansible@host:/opt/ansible/ansible> git pull --rebase Current branch devel is up to date. ansible@host:/opt/ansible/ansible> ansible@s1100tap460:/opt/ansible/ansible> git submodule update --init --recursive
Ansible provides a script which makes it easy to setup the environment:
ansible@host:/opt/ansible/ansible>cd ansible ansible@host:/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:
ansible@host:/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:
ansible@host:/opt/ansible/ansible> which ansible /opt/ansible/ansible/bin/ansible ansible@host:/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:
ansible@host:/opt/ansible/ansible> echo "127.0.0.1" >> /etc/ansible/hosts
… and then exchange the public ssh key of the ansible user:
ansible@host:~> ssh-keygen -t dsa ansible@host:~> ssh-copy-id -i ~/.ssh/id_dsa.pub [email protected]
Do a functional test:
ansible@s1100tap460:~> ansible all -m ping 127.0.0.1 | SUCCESS => { "changed": false, "ping": "pong" }
… and your done. Happy deploying …