Last active
February 10, 2023 00:51
-
-
Save schwartzmx/1d01cbf3cc07d486e1fa to your computer and use it in GitHub Desktop.
Ansible Windows EC2 Provisioning Playbook
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
- name: Launch {{env}}-{{service}} Instance(s) | |
hosts: localhost | |
gather_facts: false | |
connection: local | |
vars_files: | |
- group_vars/env/{{ environment }}.yml | |
- group_vars/service/{{ service }}.yml | |
- group_vars/admin.yml | |
# Launch instances with the following parameters. Register the output. | |
tasks: | |
- name: Launch instance | |
local_action: | |
module: ec2 | |
region: "{{region}}" | |
image: "{{image}}" | |
instance_type: "{{instance_type}}" | |
instance_profile_name: "{{iam_role}}" | |
group: "{{security_group}}" | |
key_name: "{{key_name}}" | |
vpc_subnet_id: "{{vpc_subnet_id}}" | |
assign_public_ip: "{{public_ip}}" | |
instance_tags: | |
Name: "{{service}}" | |
Environment: "{{env}}" | |
stackdriver_monitor: "{{stackdriver_monitor}}" | |
count: "{{count}}" | |
user_data: "<powershell> | |
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force\n | |
$storageDir = $pwd\n | |
$webclient = New-Object System.Net.WebClient\n | |
$url = \"https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1\"\n | |
$file = \"C:\\Program Files\\Amazon\\Ec2ConfigService\\Scripts\\ConfigureRemotingForAnsible.ps1\"\n | |
$webclient.DownloadFile($url,$file)\n | |
$VerbosePreference=\"Continue\"\n | |
& $file\n | |
$user=[adsi]\"WinNT://localhost/Administrator,user\"\n | |
$user.SetPassword(\"{{password}}\")\n | |
</powershell>" | |
wait: true | |
register: ec2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Phil, I'll be testing your playbook, can the user data also call a .ps1 file that you create?