Skip to content

Instantly share code, notes, and snippets.

View alexcheng1982's full-sized avatar
๐ŸŽ‰
AI time

Fu Cheng alexcheng1982

๐ŸŽ‰
AI time
View GitHub Profile
@alexcheng1982
alexcheng1982 / winrm-userdata.txt
Created December 14, 2017 19:20
User data to configure WinRM
<powershell>
$admin = [adsi]("WinNT://./administrator, user")
$admin.PSBase.Invoke("SetPassword", "{{ win_initial_password }}")
Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'))
</powershell>
@alexcheng1982
alexcheng1982 / launch-instances.yml
Created December 14, 2017 19:21
Launch Windows instances
---
- hosts: localhost
vars_files:
- secret.yml
gather_facts: no
tasks:
- name: create ec2 windows server security group
ec2_group:
name: "{{ aws.windows_security_group }}"
description: Windows server
@alexcheng1982
alexcheng1982 / hosts
Created December 14, 2017 19:22
Ansible hosts
localhost ansible_connection=local ansible_python_interpreter=python
[win]
[win:vars]
ansible_connection=winrm
ansible_ssh_port=5986
ansible_ssh_user=Administrator
ansible_ssh_pass={{ win_initial_password }}
ansible_winrm_server_cert_validation=ignore
@alexcheng1982
alexcheng1982 / install-aws-tools.yml
Created December 14, 2017 19:23
Install AWS tools
- name: install aws tools
win_package:
path: http://sdk-for-net.amazonwebservices.com/latest/AWSToolsAndSDKForNet.msi
arguments: '/quiet /qn /le Z:\aws-tools-installlog.txt'
product_id: '{186A6440-3AD4-4E0E-ACC2-C098CA589290}'
state: present
creates_path: 'C:\Program Files\Amazon\Ec2ConfigService'
@alexcheng1982
alexcheng1982 / config-aws.ps1
Created December 14, 2017 19:23
Configure AWS SDK
Set-AWSCredential -AccessKey {{lookup('env', 'AWS_ACCESS_KEY_ID')}} -SecretKey {{lookup('env', 'AWS_SECRET_ACCESS_KEY')}} -StoreAs default
Set-DefaultAWSRegion -Region {{aws.region}}
@alexcheng1982
alexcheng1982 / config-aws.yml
Created December 14, 2017 19:24
Configure AWS in Ansible
- name: copy aws config
win_template:
src: aws_config.ps1.j2
dest: 'Z:\aws_config.ps1'
- name: config aws sdk tools
win_shell: Z:\aws_config.ps1
@alexcheng1982
alexcheng1982 / download-s3.yml
Created December 14, 2017 19:26
Download artifacts from S3
- name: download artifact
win_command: "PowerShell.exe -Command Read-S3Object -Region {{aws.region}} -BucketName <bucket_name> -Key <key> -File {{ target_path }} "
@alexcheng1982
alexcheng1982 / install-chocolatey.ps1
Created December 14, 2017 19:27
Install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
@alexcheng1982
alexcheng1982 / install-pscx.yml
Created December 14, 2017 19:27
Install pscx
- name: install pscx
win_chocolatey:
name: pscx
state: present
@alexcheng1982
alexcheng1982 / find-exe-path.yml
Created December 14, 2017 19:29
Find exe file path
- name: find exe path
win_find:
paths: "{{ extracted_path }}"
patterns: "*.exe"
register: exe_find