A repo to test Ansible in a Windows environment.
- Clone this repo, eg:
git clone git@github.com:adamrushuk/Ansible-Windows.git
- To build an Ansible Control node and two Windows hosts, ensure you're in the root directory of this repo, then run
vagrant up
To confirm Windows connectivity, follow the steps below:
- SSH into the Ansible Control VM:
vagrant ssh ansible01
- Navigate to ansible directory:
cd /vagrant/ansible/
- To use the
win_ping
module onall
hosts in thehost
inventory file, run:
ansible all -i hosts -m win_ping
- To collect useful information (Ansible Facts) on all hosts, use the
setup
module:
ansible all -i hosts -m setup
- Facts for the Ansible Control node can be collected by running:
ansible localhost -i hosts -m setup
Default values have been specified for the Inventory
file and Roles Path
in ansible.cfg
:
[defaults]
inventory = hosts
roles_path = ${PWD}/roles
This playbook starts a service, enables telnet, and shows a different message depending on if the telnet feature was already installed or not.
- Navigate to ansible directory:
cd /vagrant/ansible/
- Run playbook:
ansible-playbook testplaybook.yml
This playbook uses serial: 1
to apply configuration to one host at a time. delegate_to: "{{ groups.webservers[0] }}"
is used so the resource is only executed on groups.webservers[0]
, even when targetting other hosts.
- Navigate to ansible directory:
cd /vagrant/ansible/
- Run playbook, showing verbose messages (
-v
):
ansible-playbook invokedsc.yml -v
NOTE: You can increase verbose mode (-vvv for more, -vvvv to enable connection debugging).
This playbook uses a role called common
to set the timezone and region / language settings.
- Navigate to ansible directory:
cd /vagrant/ansible/
- Run playbook:
ansible-playbook use_role.yml
This playbook uses the site.yml
playbook, which contains the webservers.yml
playbook. Other playbooks could be used here if required.
The webservers.yml
playbook contains the common
role, and also installs the IIS Windows Feature. A conditional reboot task is included.
- Navigate to ansible directory:
cd /vagrant/ansible/
- Run playbook:
ansible-playbook site.yml -v