Ansible: Difference between revisions

From AquaWiki
Jump to navigation Jump to search
(Created page with "== Getting Started == 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 thei...")
 
No edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Getting Started ==
== Getting Started ==
    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.
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 dnf -y install python3 vim
     sudo apt -y install python3 vim
     sudo apt -y install python3 vim


    check if pip is installed
check if pip is installed
     python3 -m pip -V
     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.   
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
     curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
     python3 get-pip.py --user
     python3 get-pip.py --user
      
      
    Install Ansible
Install Ansible
     python3 -m pip install --user 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.
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
     sudo dnf -y install ansible


    If you wanted to upgrade
If you wanted to upgrade
     python3 -m pip install --upgrade --user ansible
     python3 -m pip install --upgrade --user ansible


    Check install and version of the ansible core package
Check install and version of the ansible core package
     ansible --version
     ansible --version


    To make life easier install ansible command shell completion
To make life easier install ansible command shell completion. If using zsh, tcsh google it. and shame on you for using tcsh.
     python3 -m pop install --user argcomplete
     python3 -m pip install --user argcomplete
     activate-global-python-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?
    *https://wiki.aquarian.biz/index.php?title=Generate_SSH_Key_Pair
 
Test SSH
    ssh user@192.168.1.243
 
Ping nodes via Ansible
    ansible all -m ping


    If using zsh, tcsh google it. and shame on you for using tsch.
* https://galaxy.ansible.com/microsoft/sql
* https://galaxy.ansible.com/community/docker
* https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#downloading-a-collection-for-offline-use

Latest revision as of 14:57, 22 November 2022

Getting Started[edit]

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[edit]

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?

   *https://wiki.aquarian.biz/index.php?title=Generate_SSH_Key_Pair

Test SSH

   ssh user@192.168.1.243

Ping nodes via Ansible

   ansible all -m ping