فهرست منبع

Initial commit

David 10 سال پیش
کامیت
00fee79f34

+ 53 - 0
README.md

@@ -0,0 +1,53 @@
+
+# Planes
+
+```
+
+                              +-> | VMs(1)  |
+internet ---> | nginx(1+) | --+-> | VMs(..) |
+                              +-> | VMs(n)  |
+
+```
+
+##nginx 
+
+Tiene que:
+ 
+* Crear una ruta subdominio <--> VM:Puerto
+* Conseguir certificado Let's encrypt
+* Renovar certificados
+
+
+##VMs(k)
+
+Tiene que:
+
+* Tener distintos usuarios(unix) por cliente (señora), distintos $HOME con distintos puertos para backend.
+* Droppear TODO el trafico que no sea de nginx.
+* Backup? por proxy nginx?
+
+
+##Ansible
+
+* Crear VM nginx
+  * DO VM + Agregar a lista de nginx
+  * Instalar SSH, nginx, certbot
+  * Configurar subdominios (DO) para señoras
+  * Configurar subdominios (nginx) para señoras
+  * Conseguir certificados para señoras
+* Crear VM(k) señora
+  * DO VM + Agregar a lista de VMs existentes
+  * Instalar SSH, python, pip
+  * sacar passwd login de ssh
+  * iptables que dropee todo el trafico que no sea ssh y que no sea de VM nginx
+* Asignar señora a VM
+  * crear usuario señora, con HOME
+  * asignarle un puerto disponible a la señora
+  * Agregar (señora,VM,puerto) a lista de señoras
+
+
+##Listas/Base de datos
+
+* Lista de VMs nginx(id,ip)
+* Lista de VMs señoras (id, ip)
+* Lista de señoras (datos personales, VM-señora-id, usuario, puerto)

+ 3 - 0
chino/ansible.cfg

@@ -0,0 +1,3 @@
+
+[defaults]
+hostfile = hosts

+ 2 - 0
chino/hosts

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

+ 64 - 0
chino/minecraft_do.yml

@@ -0,0 +1,64 @@
+# http://www.ansibleworks.com/docs/modules.html#digital-ocean
+
+# Create a new Droplet
+# Will return the droplet details including the droplet id (used for idempotence)
+
+#- name: ensure ssh key present
+#module: digital_ocean
+- hosts: digitalocean
+  vars:
+    droplets:
+      - droplet-one
+      - droplet-two
+
+  tasks:
+  - name: Ensure DO ssh key present
+    digital_ocean: >
+      state=present
+      command=ssh
+      name=desktap
+      ssh_pub_key={{ lookup('file', '~/.ssh/id_rsa.pub') }}
+    register: desktap
+  
+  - name: ensure droplets exist
+    digital_ocean: >
+      state=present
+      command=droplet
+      unique_name=yes
+      name={{ item }}
+      size_id=512mb
+      region_id=nyc1
+      image_id=debian-8-x64
+      ssh_key_ids={{ desktap.ssh_key.id }}
+    with_items: "{{ droplets }}"
+    register: droplet_details
+
+  - debug: msg="IP is {{ item['droplet']['ip_address'] }}, ID is {{ item['droplet']['id']}}."
+    with_items: "{{ droplet_details.results }}"
+
+  - name: Add new droplet to host group
+    local_action: add_host hostname={{ item['droplet']['ip_address'] }} groupname=launched
+    with_items: "{{ droplet_details.results }}"
+  
+  - name: Wait for SSH to come up
+    local_action: wait_for host={{ item['droplet']['ip_address'] }} port=22 delay=10 timeout=320 state=started           
+    with_items: "{{ droplet_details.results }}"
+
+#- name: Configure droplet 
+#  hosts: launched
+#  gather_facts: True
+#  tasks:
+#    - name: apply apt-get update --fix-missing
+#      command: apt-get update --fix-missing
+#      sudo: yes
+#    - name: install screen
+#      apt: pkg=screen
+#      sudo: yes
+#    - name: make the minecraft directory
+#      file: state=directory path=/root/minecraft
+#    - name: download minecraft (1.6.4)
+#      command: wget https://s3.amazonaws.com/Minecraft.Download/versions/1.6.4/minecraft_server.1.6.4.jar chdir=/root/minecraft creates=/root/minecraft/minecraft_server.1.6.4.jar
+#      sudo: yes
+#    - name: run minecraft
+#      command: screen -S minecraft -d -m java -Xmx512M -Xms512M -jar /root/minecraft/minecraft_server.1.6.4.jar
+#      sudo: yes

+ 26 - 0
lxc/autoregister.yml

@@ -0,0 +1,26 @@
+- hosts: local
+  become: true
+  tasks:
+  - name: Create the containers
+    lxc_container:
+      template: ubuntu
+      name: "{{ item.name }}"
+      state: started
+    with_items: "{{ containers }}"
+    register: containers_info
+
+  - name: Wait for the network to be setup in the containers
+    when: containers_info|changed
+    pause: seconds=10
+
+  - name: Get containers info now that IPs are available
+    lxc_container:
+      name: "{{ item.name }}"
+    with_items: "{{ containers }}"
+    register: containers_info
+
+  - name: Register the hosts in the inventory
+    add_host:
+      name: "{{ item.lxc_container.ips.0 }}"
+      group: "{{ item.item.service }}"
+    with_items: "{{ containers_info.results }}"

+ 11 - 0
lxc/container.yml

@@ -0,0 +1,11 @@
+- hosts: local
+  tasks:
+  - name: Create a started container
+    lxc_container:
+      name: test-container-started2
+      container_log: true
+      template: ubuntu
+      state: started
+      template_options: --release trusty
+    become: yes
+    become_user: root

+ 13 - 0
web/provision.yml

@@ -0,0 +1,13 @@
+---
+- hosts: web
+  user: root
+  vars:
+    username: david
+    nginx_user: www-data
+    password: $6$9PumPdxR$kwIOv22qD8vHWFvBTrYxXsIjCvfVuM88lhCGosnf6DgtuKjkxU9m34nvkz0X/i/ooUgV1o3poIj7RijltWj5E.
+    public_key: "{{ lookup('env','HOME') }}/.ssh/id_rsa.pub"
+  roles: 
+   - common
+   - user
+   - nginx
+   - ssh

+ 10 - 0
web/roles/common/tasks/main.yml

@@ -0,0 +1,10 @@
+- name: install unattended upgrades
+  apt: name=unattended-upgrades state=present
+
+- name: Install common packages
+  apt: name={{item}} state=present
+  with_items:
+    - vim-tiny
+    - htop
+    - sudo
+    - ntp

+ 10 - 0
web/roles/nginx/handlers/main.yml

@@ -0,0 +1,10 @@
+---
+- name: restart nginx
+  service: 
+    name: nginx
+    state: restarted
+
+- name: reload nginx
+  service: 
+    name: nginx
+    state: reloaded

+ 18 - 0
web/roles/nginx/tasks/main.yml

@@ -0,0 +1,18 @@
+- name: Install Nginx
+  apt:
+    name: nginx
+    state: present
+    force: yes
+    update_cache: yes
+
+- name: Set Nginx user
+  lineinfile: 
+    dest: /etc/nginx/nginx.conf
+    regexp: "^user"
+    line: "user {{ nginx_user }};"
+    state: present
+  notify: restart nginx
+- name: copy html index
+  template:
+    src: templates/index.nginx-debian.html 
+    dest: /var/www/html/index.nginx-debian.html 

+ 4 - 0
web/roles/ssh/tasks/main.yml

@@ -0,0 +1,4 @@
+- name: add pk to user
+  authorized_key:
+    user: "{{ username }}"
+    key: "{{ lookup('file', public_key) }}"

+ 15 - 0
web/roles/user/tasks/main.yml

@@ -0,0 +1,15 @@
+- name: create admin user
+  user:
+    name: "{{ username }}"
+    system: no
+    createhome: yes
+    groups: "sudo"
+    append: yes
+    shell: "/bin/bash"
+
+
+- name: create nginx user
+  user:
+    name: "{{ nginx_user }}"
+    system: yes
+    createhome: no

+ 9 - 0
web/templates/index.nginx-debian.html

@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Welcome to nginx!</title>
+</head>
+<body>
+<h1>Welcome to nginx! Served by {{ ansible_hostname }}. </h1>
+</body>
+</html>