Ansible - tmansfield42/Tech-Journal GitHub Wiki

Ansible Automation Lab Journal

Introduction

In this lab journal, we document the process of setting up Ansible for automation tasks, preparing Linux and Windows hosts for automation, and managing Ansible-specific configuration files and playbooks. In here are commands used to install Ansible on the controller, configure hosts, and necessary files for automation.

Differences in adding users

Ubuntu -

adduser <user>

usermod -aG sudo <user>

CentOS 7 & Rocky -

useradd <user>

usermod -aG wheel <user>

Create users 'deployer' on all systems with the same password, I used 'ansible' for the password.

refer to my 00-installer-config.yaml file for Ubuntu setup, CentOS & Rocky just uses nmtui for network setup.

Installing Ansible

On controller-yourname type:

sudo apt install ansible sshpass python3-paramiko

Preparing Hosts for Automation

  • ssh-keygen -t rsa -C "sys265" - Generates an RSA keypair. Make sure to include a passphrase for this lab. Do this on controller-firstname

  • ssh-copy-id [email protected] - Copies the public key over to ansible1 and ansible2 machines

  • eval $(ssh-agent) - Tests to see if ssh-agent is running, and if not, it will run it.

  • ssh-add -t 14400 - Adds a lifetime of 14400 seconds to not have to use RSA passphrase

Managing Ansible Configuration Files and Playbooks

Uploading Configuration Files

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

Setting Powershell to be the Default Shell for SSH

  • 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

OpenSSH Not Downloading - FIXED

  • Ensure Windows Update Service is enabled and running, then proceed to download OpenSSH Server through Apps & features > Manage optional features > Add a feature > OpenSSH Server
⚠️ **GitHub.com Fallback** ⚠️