Ansible

From AquaWiki
Revision as of 13:38, 22 November 2022 by 216.81.81.80 (talk)
Jump to navigation Jump to search

Getting Started

Instead of following the below steps run this script: TBD

Feel free to clone node 1, this node already has ansible installed, and only needs it's hosts updated. Also feel free to use nodes 2 and 3 and your own hosts to experiment with ansible. I'm using node 1 on aqua cloud as the ansible controller and docker swarm master. For ansible we'd either have a dedicated controller or your laptop/workstation could be the controller.

All nodes will need to have python3, for example. After python is installed on clients there should be no need to ever log into them again, only their IP addresses or host names will be needed.

   sudo dnf -y install python3 vim
   sudo apt -y install python3 vim

check if pip is installed

   python3 -m pip -V

if not run the following. Have a look at the file if you'd like, it's the pip package zipped up and base85 encoded.

   curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
   python3 get-pip.py --user
   

Install Ansible

   python3 -m pip install --user ansible

If using Fedora ansible can also be installed with the following. For Debian/Ubuntu you'll likely need to add repos for apt, but the above will work.

   sudo dnf -y install ansible

If you wanted to upgrade

   python3 -m pip install --upgrade --user ansible

Check install and version of the ansible core package

   ansible --version

To make life easier install ansible command shell completion. If using zsh, tcsh google it. and shame on you for using tcsh.

   python3 -m pip install --user argcomplete
   sudo activate-global-python-argcomplete


Adding Hosts

Make directory

   sudo mkdir /etc/ansible

Enter IP addresses of domain names in /etc/ansible/hosts

   sudo vim /etc/ansible/hosts

Enter the following. These are nodes 1, 2, 3 on aquacloud.

   [nodes]
   192.168.1.152
   192.168.1.243
   192.168.1.244

Verify hosts in inventory

   ansible all --list-hosts

Add your public ssh key to the authorized_keys files on each remote system

   ssh-copy-id -i ~/.ssh/id_rsa.pub user@192.168.1.243

You'll likely need to type yes and press enter, then enter the password and press enter to add the key

Don't have a key pair?

   *[Generate SSH Key Pair]

Test SSH

   ssh user@192.168.1.243

Ping nodes via Ansible

   ansible all -m ping

https://galaxy.ansible.com/microsoft/sql https://galaxy.ansible.com/community/docker