Lab 04 Automation with Ansible - AdieStevens/SYS-265 GitHub Wiki

Installing Ansible

  • sudo apt install ansible sshpass python3-paramiko
  • ansible --version (see version)

Preparing Linux and Window hosts for automation

  • Prepare windows machine -
  • Service menu: start "Windows Update"
  • Then type following command
  • "Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.10"
  • "Start-Service sshd" (starts service)
  • "Set-Service -Name sshd -StartupType 'Automatic'" (This mask ssh service start automatically everytime box is booted up.
  • Now we need to set PowerShell to be the default shell for ssh, to do this type the following commands
  • "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"
  • Now you might have to add a new firewall inbound rule to allow port 22 connection for your ssh session into your windows.
  • From there you should be able to ssh into your windows by [email protected]@host-name
  • Now we update our inventory, add a "[windows]" category and put your windows boxes below
  • Now for any other windows machine you have to add you would do the same thing

Ansible Configuration

  • Now here are some screenshots of my ansible configuration files
  • This is my ansible.cfg file which specifies my inventory.txt and overrides the default config file
  • This is my inventory.txt file that defines the hosts and groups of hosts upon which commands, modules, and tasks in a playbook operate.
  • Here is a look at my roles directory which automatically load related vars, files, tasks, handlers, and other Ansible artifacts based on a known file structure.