Ansible - Brandon-Duffy/SYS-265 GitHub Wiki

First step is installing the ansible package to MGMT02. To do so enter the command:

sudo apt install ansible sshpass python3-paramiko

Setting up SSH

Create a user named deployer on all nodes that will be controlled with the same password

Next is to edit the sudoers file on linux nodes. Enter the command "sudo vi /etc/sudoers" and add this line under root:

deployer ALL=(ALL:ALL) ALL

For passwordless ssh, enter:

ssh-keygen -t rsa

For the linux VMs, use ssh-copy-id as follows to copy the public key over

image

For windows vms, create the ".ssh" directory and copy the public key to that

After doing all of those you should be able to ssh into everything without a password, but don't forget to run ssh-add -t 14400 occasionally

Setting up mgmt1

Run these commands to set up OpenSSH Server on mgmt1

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Start-Service sshd

Set-Service -Name sshd -StartupType 'Automatic'

Run the following commands for the ssh default shell to be powershell

Set-ItemProperty "HKLM:\Software\Microsoft\Powershell\1\ShellIds" -Name ConsolePrompting -Value $true

New-ItemProperty -Path HKLM:\SOFTWARE\OpenSSH -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

Creating the inventory.txt file

On mgmt2, create a new directory in deployers home directory called with mkdir -p ansible/roles and change over to it with cd ansible

Next create a file called inventory.txt and add the names or IP of each node you will be managing as such. Make sure to section them with [name]

image

And don't forget the windows vars!

Deploying an application to util

First install the docker role with ansible-galaxy install geerlingguy.docker -p roles/

Then create a .yml or .yaml playbook file to install the role as such

image

Run the playbook with ansible-playbook -i inventory.txt /roles/nameoffile.yml

After the playbook is done installing docker to util, head over to util and run yum info docker to verify the installation

image

Installing an apt package

This is going to be installed to the docker vm and the package is zabbix-agent. Install the role with ansible-galaxy install dj-wasabi.zabbix-agent

Then create the .yml or .yaml file to install the package as following

image

Run the playbook with ansible-playbook -i inventory.txt /roles/nameoffile.ym

After the playbook is done installing, head over to docker and check the installation with apt list zabbix-agent

image

Installing a yum package

The package for nagios will be installed to util. First install the role with ansible-galaxy install networklore.nagios

Then create the .yml or .yaml file to install the package as so

image

Run the playbook with ansible-galaxy -i inventory.txt /roles/nameoffile.yml

After the playbook has finished, go over to util and run yum info nagios to verify the installation

image

Adding a new Linux local user can be an SSH user or one with a password

This will be done to create a new user with a password on util

Create a .yml or .yaml file as such

image

Run the playbook file with ansible-playbook -i inventory.txt nameoffile.yml

Then verify that the new user was created by signing into the user on util

image

Adding a new Windows domain user

This playbook will be run onto mgmt1 to create the new domain user

In order for the playbook to work, you must install an ansible module for windows domain management with ansible-collection install community.windows

Then create the .yml or .yaml file as following

image

Then run the playbook file with ansible-playbook -i inventory.txt nameoffile.yml --ask-pass

After the playbook is done running, head over to mgmt1 to verify the installation by opening Server Manager and opening up Active Directory Users and Computers

Then open the Users section and find the new domain user that has been created

image

image