From 653458fcaa755cf27780c12ebf08054f74efcf69 Mon Sep 17 00:00:00 2001 From: Seyyed Soroosh Hosseinalipour Date: Sat, 19 Mar 2022 18:34:50 +0000 Subject: [PATCH] Add basic ansible. (see #19) --- Deployment/Ansible/playbooks/ansible.cfg | 11 +++++++ .../Ansible/playbooks/general-server.yaml | 18 +++++++++++ Deployment/Ansible/playbooks/hosts | 13 ++++++++ Deployment/Powershell/prepare-windows.ps1 | 32 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 Deployment/Ansible/playbooks/ansible.cfg create mode 100644 Deployment/Ansible/playbooks/general-server.yaml create mode 100644 Deployment/Ansible/playbooks/hosts create mode 100644 Deployment/Powershell/prepare-windows.ps1 diff --git a/Deployment/Ansible/playbooks/ansible.cfg b/Deployment/Ansible/playbooks/ansible.cfg new file mode 100644 index 0000000..2ec6226 --- /dev/null +++ b/Deployment/Ansible/playbooks/ansible.cfg @@ -0,0 +1,11 @@ +[defaults] +inventory = hosts +remote_user = ssoroosh +port = 22 +host_key_checking = False + +[privilege_escalation] +become = True +become_method = sudo +become_user = root +become_pass = a diff --git a/Deployment/Ansible/playbooks/general-server.yaml b/Deployment/Ansible/playbooks/general-server.yaml new file mode 100644 index 0000000..acd3958 --- /dev/null +++ b/Deployment/Ansible/playbooks/general-server.yaml @@ -0,0 +1,18 @@ +# ITNOA + +- name: Install vim + hosts: workers + become: True + tasks: + - name: Ansible Upgrade all Packages + register: updatesys + apt: + upgrade: full + state: latest + update_cache: yes + cache_valid_time: 3600 + - name: Display the last line of the previous task to show that the cache was updated + debug: + msg: "{{updatesys.stdout}}" + - name: install vim + apt: name=vim state=latest \ No newline at end of file diff --git a/Deployment/Ansible/playbooks/hosts b/Deployment/Ansible/playbooks/hosts new file mode 100644 index 0000000..7fbfbaa --- /dev/null +++ b/Deployment/Ansible/playbooks/hosts @@ -0,0 +1,13 @@ +# ITNOA + +[workers] +host1 ansible_host=172.22.64.3 +host2 ansible_host=172.22.64.4 +host3 ansible_host=172.22.64.5 +host4 ansible_host=172.22.64.6 + +[all:vars] +ansible_connection=ssh +ansible_user=ssoroosh +ansible_ssh_pass=a +ansible_become_pass=a diff --git a/Deployment/Powershell/prepare-windows.ps1 b/Deployment/Powershell/prepare-windows.ps1 new file mode 100644 index 0000000..639f430 --- /dev/null +++ b/Deployment/Powershell/prepare-windows.ps1 @@ -0,0 +1,32 @@ +# ITNOA + +Install-Module 7Zip4PowerShell -Scope CurrentUser -Force -Verbose + +# Install choco +Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) + +# Install Ubuntu On Windows +Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux + +Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile ~/Ubuntu.zip -UseBasicParsing + +# OpenSSH +# Install the OpenSSH Client +Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 + +# Install the OpenSSH Server +Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 + +# Start the sshd service +Start-Service sshd + +# OPTIONAL but recommended: +Set-Service -Name sshd -StartupType 'Automatic' + +# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify +if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) { + Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..." + New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 +} else { + Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists." +} \ No newline at end of file