Manage Windows Using Ansible

Setup openssh (prerequisites) Before using ansible to manage windows, make sure that openssh is installed and enabled. If not, you can use this powershell script to do so: $sshServer = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*' if ($sshServer.State -ne 'Installed') { Write-Host "Installing OpenSSH Server..." Add-WindowsCapability -Online -Name $sshServer.Name } else { Write-Host "OpenSSH Server is already installed." } # Set default shell to powershell for ansible if (-not (Get-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -ErrorAction SilentlyContinue)) { Write-Host "Set default shell to powershell....

November 20, 2024 · 2 min

Ansible Utils Commands

NB: As an example, the machines are defined in file inventory.yaml with the following content: # VMs all: hosts: vm01: vm02: vm03: vm04: vm05: vm06: # Groups dev: hosts: vm01: vm02: test: hosts: vm03: vm04: prod: hosts: vm05: vm06: # Parent Groups lan: children: dev: test: wan: children: prod: ⚠ If you did not name your inventory file inventory.yaml at root folder, you’ll need to add the argument -i <inventory_filename> to all the commands in the following post....

August 23, 2024 · 2 min

Ansible Data Structures

Type of data structures Since Ansible is based on Python. There are two main data structures in Ansible: list and dictionary. List Initialization of a list - name: Initialize an empty list set_fact: list: [] Result is: {"list": []} Append element to a list - name: Append element to list set_fact: list: "{{ list + [ 'element_1' ] }}" Result is: {"list": ["element_1"]} Append multiple elements to a list - name: Get list of files in current directory shell: "ls" register: ls_files - name: Append filtered elements (only yaml file) to list set_fact: list: "{{ list + [ item ] }}" loop: "{{ ls_files....

December 18, 2023 · 3 min