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 / 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 / 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 / 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 / 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 / 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 / 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 / ansible-docker
Created December 14, 2017 19:18
Ansible Docker file
FROM williamyeh/ansible:ubuntu16.04
RUN pip install --upgrade pip && \
pip install boto3 && \
pip install boto
ADD ansible /etc/ansible
RUN chmod +x /etc/ansible/ec2.py
@alexcheng1982
alexcheng1982 / jetty_password.sh
Created December 12, 2017 16:52
Obfuscate Jetty password
java -cp jetty-util-9.2.17.v20160517.jar org.eclipse.jetty.util.security.Password password
@alexcheng1982
alexcheng1982 / HttpsConnector.java
Created December 12, 2017 16:50
Jetty Https Connector
final SslContextFactory sslContextFactory = new SslContextFactory(keyStorePath);
sslContextFactory.setKeyStorePassword(keyStorePassword);
final HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
httpsConfiguration.addCustomizer(new SecureRequestCustomizer());
final ServerConnector httpsConnector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(httpsConfiguration));
httpsConnector.setPort(httpsPort);
server.addConnector(httpsConnector);
@alexcheng1982
alexcheng1982 / HttpConnector.java
Last active December 12, 2017 16:54
Jetty HttpConnector
final Server server = new Server();
final HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setSecureScheme("https");
httpConfiguration.setSecurePort(httpsPort);
final ServerConnector http = new ServerConnector(server,
new HttpConnectionFactory(httpConfiguration));
http.setPort(httpPort);
server.addConnector(http);