% % Ansible.tex % % Fork Sand IT Manual % % Copyright (C) 2018, Fork Sand, Inc. % Copyright (C) 2017, Jeff Moe % % This document is licensed under the Creative Commons Attribution 4.0 % International Public License (CC BY-SA 4.0) by Fork Sand, Inc. % \section{Ansible Cloud Management} Use \texttt{ansible} for management of servers. \begin{itemize} \item Ansible --- Website: \\ \url{https://ansible.com} \item Ansible Github --- Repo: \\ \url{https://github.com/ansible/ansible.git} \item DebOps: \url{https://docs.debops.org/en/latest/index.html} \end{itemize} \subsection{Build Ansible Debian Package} The version of Ansible is 2.2 in Debian 9 (stable/Stretch). The current stable release is Ansible 2.4. Below documents how to build a 2.4 package for Debian 9. \begin{minted}{sh} # To build a Debian package: # Check here for latest version: # https://packages.debian.org/sid/ansible wget http://http.debian.net/debian/pool/main/a/ansible/ansible_2.4.0.0+dfsg-1.debian.tar.xz wget http://http.debian.net/debian/pool/main/a/ansible/ansible_2.4.0.0+dfsg.orig.tar.gz # Install some deps apt-get install debhelper python-all python-crypto python-setuptools python-yaml asciidoc python-nose python-passlib dh-python tar xf ansible_2.4.0.0+dfsg.orig.tar.gz cd ansible-2.4.0.0/ tar xf ../ansible_2.4.0.0+dfsg-1.debian.tar.xz # Update version: echo -n " -- Jeff Moe " ; date "+%a, %d %b %Y %H:%M:%S %z" vim debian/changelog dpkg-buildpackage -rfakeroot -S -uc -us -sa dpkg-buildpackage -rfakeroot -b -uc # That will produce this file to be installed: dpkg -i ansible_2.4.0.0+dfsg-2_all.deb apt-get -f install # If you want the Ansible git archive: git clone https://github.com/ansible/ansible.git --recursive \end{minted} \subsection{Ansible Initial Configuration} Here is how to set up Ansible after initially installing it. This is run on the system adminstrator's workstation. \begin{minted}{sh} # Quick and dirty test by setting up a host and running `uptime`. mkdir -p ~/.ansible echo ns1 > ~/.ansible/hosts ansible -i ~/.ansible/hosts ns1 -a 'uptime' \end{minted} \begin{minted}{sh} ~/.ansible.cfg [defaults] inventory = $HOME/.ansible/hosts [ssh_connection] ssh_args = -o ControlMaster=auto -o ControlPersist=300s pipelining = True \end{minted} To generate a full list of \texttt{ns} hosts, run the script: \begin{minted}{sh} cd source/resources/servers echo "[ns]" > ~/.ansible/hosts ./ns-serverlist-ansible.sh >> ~/.ansible/hosts ansible -i ~/.ansible/hosts ns -a "uptime" # Find the failed hosts and remove them from ~/.ansible/hosts. echo "[ns]" > ~/.ansible/hosts.tmp ansible -f 32 -i ~/.ansible/hosts ns -a "echo" | grep ^ns | grep SUCCESS | cut -f 1 -d " " | sort -V >> ~/.ansible/hosts.tmp mv ~/.ansible/hosts ~/.ansible/hosts.old mv ~/.ansible/hosts.tmp ~/.ansible/hosts # Test it works: ansible -i ~/.ansible/hosts ns -a "uptime" # To get a ton of info about each host: ansible -i ~/.ansible/hosts ns -m setup \end{minted} XXX Fix, make sure everyone has \texttt{/usr/bin/python} available for \texttt{ansible}: \begin{minted}{sh} # XXXX SOME HOSTS DON'T HAVE /usr/bin/python # JUST PYTHON3. HOSTS THAT DIDN'T HAVE /usr/bin/python: # (ALL OVH) # ns14 ns15 ns21 ns22 apt install python python-minimal \end{minted} Set up some playbooks, grab examples: \begin{minted}{sh} git clone https://github.com/ansible/ansible-examples.git cd ansible-examples/ \end{minted}