Created
June 9, 2017 05:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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