Installing Ansible with winrm module for Windows server automation
by Jephe Wu - http://linuxtechres.blogspot.com
Steps
set proxy for /etc/yum.conf
proxy= http://proxy.domain.com:8080
Disable redhat registration
[root@ansible01 pluginconf.d]# grep enabled /etc/yum/pluginconf.d/subscription-manager.conf
enabled=0
Install EPEL release for yum repo
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Download and install ansible packages from EPEL together with local RHEL7 ISO mount
yum localinstall * => install all below packages
Testing playbook
[root@ansible01 ~]# more hosts.ini
[win:vars]
ansible_user='DOMAIN\jephe'
ansible_password=xxxxxxxxxxx
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
#ansible_winrm_scheme=http
ansible_port=5985
#ansible_winrm_transport=kerberos
#ansible_winrm_transport=credssp
ansible_winrm_transport=ntlm
[win]
192.168.1.10
root@ansible01 ~]# ansible -i hosts.ini win -m win_ping
192.168.1.10 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@ansible01 ~]# more win_play.yml
---
- name: test
hosts: all
become_method: runas
tasks:
- name: whoami
win_shell: mkdir c:\tmp\jewu2
[root@ansible01 ~]# ansible-playbook -i hosts.ini win_play.yml
PLAY [test] ****************************************************************************************************************************************
TASK
[Gathering Facts]
*****************************************************************************************************************************
ok: [192.168.1.10]
TASK
[whoami]
**************************************************************************************************************************************
changed: [192.168.1.10]
PLAY RECAP *****************************************************************************************************************************************
192.168.1.10 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
===============