1
0
mirror of https://github.com/elisspace/Wakanda-Forever.git synced 2026-08-29 15:44:11 +00:00
This commit is contained in:
q0phi80
2022-07-23 21:29:28 -04:00
parent de91bd6d34
commit c4ef57ce31
5 changed files with 101 additions and 4 deletions

62
imager/imager.py Normal file
View File

@@ -0,0 +1,62 @@
#!/usr/bin/python
# Borrowed code from https://github.com/xpn/DemoLab/tree/master/imager
import winrm
import boto3
import time
internal_domain_user = "tsankara"
internal_domain_pass = "Password@1"
class WinRMSession:
def __init__(self, host, username, password, use_ntlm=False):
self.host = host
self.username = username
self.password = password
self.use_ntlm = use_ntlm
def run_command(self, command, args=[]):
if self.use_ntlm:
s = winrm.Session(self.host, auth=(self.username, self.password), transport="ntlm")
else:
s = winrm.Session(self.host, auth=(self.username, self.password))
try:
r = s.run_cmd(command, args)
print("=====[ STDERR ]=====")
print(r.std_err.decode("ascii"))
print("=====[ STDOUT ]=====")
return r.std_out.decode("ascii")
except InvalidCredentialsError as e:
print("Error")
def clean_windows_image(username, password, ip, domain_joined):
print("====[ Cleaning {0} ]====".format(ip))
dsc = "Write-Output '[DscLocalConfigurationManager()]' 'Configuration Meta { Node localhost { Settings { RefreshMode = \'\'Disabled\'\' } } }' > C:\\windows\\temp\\meta.ps1"
s = WinRMSession(ip, username, password, use_ntlm=domain_joined)
print(s.run_command('powershell', ['-c', 'Remove-DscConfigurationDocument -Stage Current -Force']))
print(s.run_command('powershell', ['-c', 'Remove-DscConfigurationDocument -Stage Previous -Force']))
print(s.run_command('powershell', ['-c', dsc]))
print(s.run_command('powershell', ['-ep', 'bypass', '-c', 'cd C:\\windows\\temp; . .\\meta.ps1; Meta; Set-DscLocalConfigurationManager -Path .\Meta']))
# First we need to clean up Windows resources
ec2 = boto3.resource('ec2')
response = ec2.instances.filter(Filters=[{'Name': 'tag:Workspace', 'Values': ['imager']},{'Name': 'instance-state-name', 'Values': ['running']}])
for instance in response:
if instance.platform == "windows":
clean_windows_image(internal_domain_user, internal_domain_pass, instance.public_ip_address, True)
# Now everything is cleaned up, we image
for instance in response:
for kv in instance.tags:
if kv["Key"] == "Name":
print("====[ Creating AMI For {0}]====".format(kv["Value"]))
name = kv["Value"] + "-{0}".format(time.time())
instance.create_image(Name=name,Description="Wakanda Imager")

19
imager/requirements.txt Normal file
View File

@@ -0,0 +1,19 @@
boto3==1.12.36
botocore==1.15.36
certifi==2020.4.5.1
# cffi==1.14.0
chardet==3.0.4
cryptography==2.9
docutils==0.15.2
idna==2.9
jmespath==0.9.5
ntlm-auth==1.4.0
pycparser==2.20
python-dateutil==2.8.1
pywinrm==0.4.1
requests==2.23.0
requests-ntlm==1.1.0
s3transfer==0.3.3
six==1.14.0
urllib3==1.25.8
xmltodict==0.12.0

View File

@@ -202,7 +202,7 @@ resource "aws_instance" "ramonda" {
}
}
# Join the Windows 10 box to the domain bast
# Join the Windows 10 box to the domain bast
provisioner "remote-exec" {
inline = [
"powershell -ExecutionPolicy Bypass -File C:/Windows/Temp/join-domain.ps1"
@@ -396,6 +396,9 @@ resource "null_resource" "guac-server-setup" {
}
resource "null_resource" "guacozy-server-setup" {
depends_on = [
null_resource.guac-server-setup
]
connection {
type = "ssh"
host = aws_instance.guac-server.public_ip
@@ -404,7 +407,7 @@ resource "null_resource" "guacozy-server-setup" {
private_key = file(var.PATH_TO_PRIVATE_KEY)
agent = false
}
provisioner "file" {
source = "./files/playbook.yml"
destination = "/tmp/playbook.yml"
@@ -420,7 +423,7 @@ resource "null_resource" "guacozy-server-setup" {
"sleep 10",
"cd /tmp/",
"ansible-playbook playbook.yml",
/* "sudo chmod +x /tmp/guacozy.sh",
/* "sudo chmod +x /tmp/guacozy.sh",
"sudo /tmp/guacozy.sh" */
]
on_failure = continue

View File

@@ -0,0 +1,13 @@
---
- become: true
hosts: localhost
name: Run Guacozy docker
tasks:
# - copy:
# src: ./files/docker-compose.yml
# dest: /tmp/docker-compose.yml
- name: Change into the tmp folder and run docker-compose
become: true
shell: sudo docker-compose -f /tmp/docker-compose.yml up -d
#chdir: /tmp/

View File

@@ -7,7 +7,7 @@ curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
apt install git -y
apt-get update -y
apt install -y python3-pip
apt install -y python3-pip ansible
sudo curl -L https://github.com/docker/compose/releases/download/1.25.3/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose