ansible on wsl and windows host
readme ansible usage
init ansible control node
install ansible on linux subsystem for windows
sudo apt update
sudo apt install python3
sudo apt install pipx
sudo apt-get install sshpass
pipx install ansible-core
pipx inject ansible-core pywinrm
pipx ensurepath
ansible-galaxy collection install ansible.windows
ansible-galaxy collection install chocolatey.chocolatey
ansible-galaxy collection install community.general
init mac client
on mac host
enable remote login/administration (a.k.a. ssh)
init windows client
on windows host
winrm quickconfig
Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value $true
winrm get winrm/config/Service
winrm get winrm/config/Winrs
New-SelfSignedCertificate -DnsName "surface3" -CertStoreLocation Cert:\LocalMachine\My
echo 239A0571A14A35C470AB3B6F3EF5181A61E557D3
winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname="surface3"; CertificateThumbprint="239A0571A14A35C470AB3B6F3EF5181A61E557D3"}'
winrm e1 winrm/config/listener
configure ansible
create hosts.ini
[win]
172.25.240.1
[win:vars]
ansible_connection=winrm
ansible_port=5986
ansible_winrm_server_cert_validation=ignore
ansible_winrm_transport=ntlm
ansible_user=userXXXXX
ansible_password=pwXXXXX
[mac]
192.168.69.44
[mac:vars]
ansible_connection=ssh
ansible_user=userXXXXX
ansible_password=pwXXXXXXX
run ansible ping command
manfred@surface3:~$ ansible win -i hosts.ini -m win_ping
172.25.240.1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
create first playbook default-sw-install.yml
- name: default-sw-install
gather_facts: true
hosts: win
tasks:
- name: install 7-zip
win_chocolatey:
name: 7zip
state: present
run 7-zip install with
ansible-playbook -i hosts.ini default-sw-install.yml
encrpt passwords in hosts.yml (changed from hosts.ini)
ansible-vault encrypt_string (pw-to-be-encrypted) --ask-vault-pass echo edit hosts.yml ansible-playbook -vv -i hosts.yml default-sw-install.yml --ask-vault-pass