Letsgo lxc containerji delajo

main
Gasper Spagnolo 2022-11-03 15:20:47 +01:00
parent 5bf22d9405
commit a8bd509bf3
59 changed files with 222 additions and 68 deletions

View File

@ -39,7 +39,7 @@ You shuold firstly specify server in the `invenvtory` file. Then start the root
* then create another lxc container for FORCAD and set it up
- [x] create N teams
- [ ] ~~fix docker installation~~ fuck that, we will install everything in lxc containers; no docker on bare metal!
- [ ] **LXC SUBNETS** <- main focus
- [x] fix docker installation
- [x] **LXC CONTAINERS** <- main focus
- [ ] VPN
- [ ] test

View File

@ -0,0 +1,36 @@
---
- name: Setup ForcAD infra
hosts: localhost
become: true
vars_files:
- './vars/main.yml'
vars_prompt:
- name: "n_teams"
prompt: "How many teams do you wish me to create?"
private: false
tasks:
- name: Setup team lxc containers and services
include_role:
name: lxd_teams
tasks_from: main
- name: Setup ForcAD infra
hosts: just_created
become: true
connection: lxd
vars_files:
- './vars/main.yml'
tasks:
- name: Install docker on all containers
include_role:
name: docker
tasks_from: main
- name: Copy services and start them
include_role:
name: services
tasks_from: main

View File

@ -0,0 +1,2 @@
[forc_ad]
localhost ansible_connection=local

View File

@ -1,27 +1,27 @@
---
- name: Install required apt packages for Docker
apt:
pkg:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- gnupg
- lsb-release
#- software-properties-common
- python3-pip
- virtualenv
- python3-setuptools
update_cache: true
##### WARNING OUTDATED!!! NEED FIX ASAP
#- name: Add Docker GPG apt Key
# apt_key:
# url: 'https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg'
# state: present
#
#- name: Add Docker Repository
# apt_repository:
# repo: 'deb https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable'
# state: present
- name: Add Docker GPG apt Key
apt_key:
url: 'https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg'
state: present
- name: Add Docker Repository
apt_repository:
repo: 'deb https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable'
state: present
- name: Install Docker
apt:

View File

@ -0,0 +1,44 @@
---
- name: Create N started containers
community.general.lxd_container:
name: "team{{ item }}"
ignore_volatile_options: true
state: started
config:
"security.nesting": "true"
source:
protocol: simplestreams
type: image
mode: pull
server: https://images.linuxcontainers.org
alias: ubuntu/20.04/cloud
profiles: ["default"]
wait_for_ipv4_addresses: true
timeout: 600
loop: "{{ range(1, n_teams|int + 1 , 1) | list }}"
register: lxc_container_create_output
#
#- name: Check python is installed in container
# delegate_to: "team{{ item }}"
# ansible.builtin.raw: dpkg -s python
# register: python_install_check
# failed_when: python_install_check.rc not in [0, 1]
# changed_when: false
# loop: "{{ range(1, n_teams|int + 1 , 1) | list }}"
#
#
#- name: Install python in container
# delegate_to: "team{{ item }}"
# ansible.builtin.raw: apt-get install -y python
# when: python_install_check.rc == 1
# loop: "{{ range(1, n_teams|int + 1 , 1) | list }}"
- name: h
debug:
msg: "{{ lxc_container_create_output.results[0].invocation.module_args.name }}"
- add_host:
hostname: "{{ lxc_container_create_output.results[item].invocation.module_args.name }}"
groups: just_created
loop: "{{ range(0, n_teams|int, 1) | list }}"

View File

@ -0,0 +1,23 @@
---
- name: Create services directory
ansible.builtin.file:
path: "/root/services"
state: directory
mode: '0755'
- name: Copy services
ansible.builtin.copy:
src: "services/"
dest: "/root/services"
mode: '0755'
# maybe list the services in directory firstly, for now its ok
- name: Start services
community.docker.docker_compose:
project_src: "/root/services/{{ item }}/service"
state: present
with_items:
- BabySql

View File

@ -1,22 +0,0 @@
---
- name: Setup ForcAD infra
hosts: forc_ad
become: true
vars_files:
- './vars/main.yml'
vars_prompt:
- name: "n_teams"
prompt: "How many teams do you wish me to create?"
private: false
tasks:
# - name: install and setup forcad
# include_role:
# name: forcad
# tasks_from: main
- name: Setup team lxc containers and services
include_role:
name: services
tasks_from: main

View File

@ -1,32 +0,0 @@
---
- name: Ensure lxd is installed
community.general.snap:
name:
- lxd
- name: Run lxd init
ansible.builtin.command:
cmd: 'lxd init --auto'
- name: Create a started container
community.general.lxd_container:
name: mycontainer
ignore_volatile_options: true
state: started
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
protocol: simplestreams # if you get a 404, try setting protocol: simplestreams
alias: ubuntu:22.04
profiles: ["default"]
wait_for_ipv4_addresses: true
timeout: 600
- name: Test
ansible.builtin.shell: lxc exec mycontainer -- sh -c "ping -c 5 google.com"
register: output
- name: h
debug:
msg: "{{ output }}"

View File

@ -0,0 +1,13 @@
---
- name: Setup ForcAD infra
hosts: forc_ad
become: true
gather_facts: false
vars_files:
- './vars/main.yml'
tasks:
- name: Setup host server
include_role:
name: ansible_lxd
tasks_from: main

View File

@ -0,0 +1,13 @@
---
- name: Nuke ForcAD infra
hosts: forc_ad
become: true
vars_files:
- './vars/main.yml'
tasks:
- name: Destory forcAD
include_role:
name: destroy
tasks_from: main

View File

@ -0,0 +1 @@
ansible-core==2.13.4

View File

@ -0,0 +1,7 @@
# ansible-galaxy collection list
collections:
- name: community.docker
version: '3.1.0'
- name: community.general
version: '5.6.0'

View File

@ -0,0 +1,53 @@
---
# - name: Make sure apt packages are available
# ansible.builtin.apt:
# pkg:
# - python3
# - python3-venv
# - python3-pip
# - virtualenv
# - snap
# update_cache: true
#
# - name: Ensure lxd is installed
# community.general.snap:
# name:
# - lxd
#
# - name: Run lxd init
# ansible.builtin.command:
# cmd: 'lxd init --auto'
#
# - name: Create a project directory
# ansible.builtin.file:
# path: /root/deploy
# state: directory
# mode: '0755'
#- name: Copy project directory
# ansible.builtin.copy:
# src: '../../../../containers_init'
# dest: /root/deploy
# mode: '0655'
- name: Create venv ans install requirements
ansible.builtin.pip:
requirements: "{{ item }}"
virtualenv: "/root/deploy/containers_init/.venv"
virtualenv_python: python3
with_items:
- "/root/deploy/containers_init/requirements.txt"
- name: Install ansible-galaxy dependencies
ansible.builtin.command:
cmd: /root/deploy/containers_init/.venv/bin/ansible-galaxy install -r /root/deploy/containers_init/requirements.yml
# - name: Run ansible playboook
# ansible.builtin.command:
# cmd: /root/deploy/containers_init/.venv/bin/ansible-playbook /root/deploy/containers_init/deploy_forcad.yml
# register: playbook_log
#
# - name: Log playbook actions
# debug:
# msg: "{{ playbook_log }}"

16
server_init/vars/main.yml Normal file
View File

@ -0,0 +1,16 @@
---
# Default directory for forcAD files
forc_ad_directory: '/forc_ad'
# forcAD download link
forc_ad_link: 'https://github.com/pomo-mondreganto/ForcAD/releases/download/v1.4.0/ForcAD_v1.4.0.zip'
# forcAd zipfile
forc_ad_zipfile: 'ForcAD_v1.4.0.zip'
# forcAD creds
admin_username: 'forcad'
admin_password: 'forcad420'
# Startime for the game
start_time: '2019-11-30 15:30:00'