Skip to content

Instantly share code, notes, and snippets.

@rbigeard
Created June 9, 2017 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbigeard/6906542b640cb635c5d3e20b616e43f0 to your computer and use it in GitHub Desktop.
Save rbigeard/6906542b640cb635c5d3e20b616e43f0 to your computer and use it in GitHub Desktop.
Ansible spin up of Windows servers in AWS and automated retrieval of automatically generated password
---
- hosts: localhost
vars:
- aws_region: "ap-southeast-2"
tasks:
- name: launch Windows Ansible Test cloudformation stack
cloudformation:
stack_name: "AnsibleWindowsTest1"
region: "{{ aws_region }}"
state: "present"
template: "windows_template.yml"
- ec2_remote_facts:
filters:
instance-state-name: running
"tag:Name": WindowsAnsibleTest
region: "{{ aws_region }}"
register: instance_details
- name: display instance details
debug: "msg={{ instance_details }}"
- name: getting windows password
ec2_win_password:
instance_id: "{{ instance_details.instances[0].id }}"
key_file: "/media/psf/Home/Documents/Kloud/MyWindowsKey.pem"
wait: yes
region: "{{ aws_region }}"
register: win_password_output
- name: adding host to inventory
add_host:
name: windows_test_host
ansible_host: "{{ instance_details.instances[0].public_dns_name }}"
ansible_password: "{{ win_password_output.win_password }}"
groups: ec2_windows
ansible_winrm_server_cert_validation: ignore
ansible_connection: 'winrm'
ansible_user: Administrator
ansible_port: 5986
- hosts: windows_test_host
roles:
- webserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment