Integrated proxmox

This commit is contained in:
2018-02-12 08:42:17 -05:00
parent 19f64d5239
commit f0197a62a0
14 changed files with 172 additions and 20 deletions

BIN
.requirements.txt.swp Normal file

Binary file not shown.

View File

@@ -11,3 +11,7 @@ home_pub_key: https://raw.githubusercontent.com/jcwimer/ubuntu-template/master/p
standard_user: cody
git_user: "Jacob Cody Wimer"
git_email: "jacob.wimer@gmail.com"
proxmox_user: "root@pam"
proxmox_host: "10.0.0.153"
proxmox_password: "{{ lookup('env', 'PROXMOX_PASSWORD') }}"
ubuntu_template_vm_name: "ubuntu-server-1404"

5
hosts
View File

@@ -1,4 +1,4 @@
#[standard]
[standard]
#wiki.wimer.local
#swarm-manager-01.wimer.local
#swarm-manager-02.wimer.local
@@ -8,6 +8,7 @@
#elk.wimer.local
#guacamole.wimer.local
#fileserver.wimer.local
test2 ansible_host=10.0.0.152
[developer-machines]
codydev ansible_host=10.0.0.207
#codydev ansible_host=10.0.0.207

52
playbooks/kvm.yml Normal file
View File

@@ -0,0 +1,52 @@
---
- name: Create machine and set up ip
hosts: all
user: root
gather_facts: no
serial: 1
tasks:
- name: Clone VM
delegate_to: localhost
proxmox_kvm:
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
clone : "{{ ubuntu_template_vm_name }}"
name : '{{ inventory_hostname }}'
node : 'rack2'
storage : 'SSD1'
format : 'qcow2'
timeout : 3000
register: cloned
- name: Wait 10 seconds for proxmox to register the new node
wait_for: timeout=10
delegate_to: localhost
- name: Start VM
delegate_to: localhost
proxmox_kvm:
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
name: '{{ inventory_hostname }}'
node: rack2
state: started
when: cloned.changed
- name: Wait for connection
delegate_to: 10.0.0.211
wait_for_connection:
delay: 60
timeout: 180
when: cloned.changed
- include: ../roles/configure-interfaces/tasks/main.yml
delegate_to: 10.0.0.211
when: cloned.changed
- name: wait for connection
wait_for_connection:
delay: 60
timeout: 180

33
playbooks/lxc-test.yml Normal file
View File

@@ -0,0 +1,33 @@
---
- name: Create LXC
hosts: localhost
user: cody
serial: 100%
tasks:
- name: Create it
proxmox:
node: 'rack2'
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
password: "{{ proxmox_password }}"
hostname: '{{ inventory_hostname }}'
memory: 512
cores: 2
swap: 4096
disk: 50
state: present
netif: '{"net0":"name=eth0,gw=10.0.0.1,ip={{ ansible_host }}/24,bridge=vmbr0"}'
ostemplate: 'local:vztmpl/ubuntu-14.04-standard_14.04-1_amd64.tar.gz'
searchdomain: wimer.local
pubkey: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDHCdYYL9IWTXyOo4qoTBkn2dlV+EKZdir5ApnLcn7yJtI89Y3UP/X4ZNtI4ZU28bCooBoYryD49XvmBXRPujMP2WR9EL9oMz5fLgow8fjYxp6zMfkBsdDBKaxJN7gx5p0JT2zRFAEmQzP085FjauPT8J7vDm2tgumYgpoze6/BmknISkJ7Ib+Opkig/JI3syHKnRij/mnN70W2lpAISaqvPXTQBX3/VWNPCWunDJfbsmMAIJU+mMDYERFKdIt3J2e8KYjYl9DRecsZFG/xLKNF54U/8LnW8pTLzoPW+Q9sPMg2/GH+JyE3Fv5xr5l+J5bm4j8i4GBuFPL0vIqBjvH cody@codydev'
- name: Turn in on
proxmox:
node: 'rack2'
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
hostname: '{{ inventory_hostname }}'
state: started

View File

@@ -4,6 +4,13 @@
# ansible-playbook -i ${project_dir}/hosts ${project_dir}/playbooks/site.yml \
# -extra-vars "home_pub_key=<pub-key-location-to-curl> standard_user=<user_name> git_user=<git-user> git_email=<git-email>"
- name: Install ansible dependencies
hosts: all
user: root
gather_facts: no
serial: 100%
tasks:
- include: ../roles/ansible-dependencies/tasks/main.yml
- name: Apply common configuration to all nodes
hosts: all

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
ansible==2.4.0.0
proxmoxer==1.0.2

View File

@@ -0,0 +1,11 @@
---
- name: Install package dependencies
raw: apt-get update -qq && apt-get install -y python-simplejson python-urllib3 python-openssl python-pyasn1 python-pip ca-certificates
- name: Install pip dependencies
raw: pip install ndg-httpsclient
ignore_errors: true
- name: Install pip dependencies again because it fails sometimes
raw: pip install ndg-httpsclient
ignore_errors: true

View File

@@ -40,6 +40,15 @@
- build-essential
- tmux
- name: Create standard user
user:
name: "{{ standard_user }}"
groups:
- sudo
- docker
state: present
shell: /bin/bash
- name: Add standard_user to docker group
user:
name: "{{ standard_user }}"
@@ -54,21 +63,9 @@
state: present
key: "{{ home_pub_key }}"
- git_config:
name: user.name
value: "{{ git_user }}"
become: yes
become_user: "{{ standard_user }}"
- git_config:
name: user.email
value: "{{ git_email }}"
become: yes
become_user: "{{ standard_user }}"
- name: Docker compose version
get_url:
url: https://github.com/docker/compose/releases/download/{{docker_compose_version_to_install}}/docker-compose-`uname -s`-`uname -m`
url: "https://github.com/docker/compose/releases/download/{{docker_compose_version_to_install}}/docker-compose-{{ ansible_system }}-{{ ansible_userspace_architecture }}"
dest: /usr/local/bin/docker-compose
mode: 755
@@ -79,6 +76,14 @@
- name: Replace sudoers file
template: src=../roles/common/templates/sudoers.j2 dest=/etc/sudoers
- name: Create /etc/docker
file:
path: /etc/docker
group: root
owner: root
mode: 700
state: directory
- name: Replace docker daemon file
template: src=../roles/common/templates/docker-daemon.json.j2 dest=/etc/docker/daemon.json
register: dockerdaemon
@@ -104,11 +109,10 @@
line="{{ nfs_location }}:/volumeUSB1/usbshare/raw-files/fileserver/shares/lab-data /data nfs defaults 0 0"
- name: Mount USB lab data directory
when: not data_mounted.stat.exists
mount:
path: /data
src: 10.0.0.150:/volumeUSB1/usbshare/raw-files/fileserver/shares/lab-data
state: present
state: mounted
fstype: nfs
- name: test for swap partition
@@ -119,6 +123,7 @@
- name: create swapfile
when: swapfile|failed
shell: fallocate -l 4G /swapfile
ignore_errors: yes
- name: set swapfile permissions
when: swapfile|failed
@@ -134,6 +139,7 @@
- name: enable swap
when: swapfile|failed
shell: swapon /swapfile
ignore_errors: yes
- name: add swapfile
when: swapfile|failed
@@ -144,7 +150,8 @@
- name: set swappiness (temporarily)
when: swapfile|failed
shell: echo 10 | tee /proc/sys/vm/swappiness
shell: echo 10 > /proc/sys/vm/swappiness
ignore_errors: yes
- name: set swappiness (permanent)
when: swapfile|failed
@@ -155,7 +162,8 @@
- name: set cache pressure (temporarily)
when: swapfile|failed
shell: echo 50 | tee /proc/sys/vm/vfs_cache_pressure
shell: echo 50 > /proc/sys/vm/vfs_cache_pressure
ignore_errors: yes
- name: set cache pressure (permanent)
when: swapfile|failed

View File

@@ -0,0 +1,15 @@
---
- name: Copy interface file
template: src=../roles/configure-interfaces/templates/interfaces dest=/etc/network/interfaces
- name: Copy interface cfg file
vars:
interface_name: eth0
template: src=../roles/configure-interfaces/templates/eth.cfg.j2 dest=/etc/network/interfaces.d/'{{ interface_name }}'.cfg
- name: Up down interface
raw: ifdown {{ interface_name }} && ifup {{ interface_name }}
vars:
interface_name: eth0

View File

@@ -0,0 +1,7 @@
auto {{ interface_name }}
iface {{ interface_name }} inet static
address {{ ansible_host }}
netmask 255.255.255.0
gateway 10.0.0.1
dns-nameservers 10.0.0.204

View File

@@ -0,0 +1,6 @@
auto lo
iface lo inet loopback
# The primary network interface
source /etc/network/interfaces.d/*.cfg

View File

@@ -105,7 +105,7 @@
mount:
path: /raw-files
src: 10.0.0.150:/volumeUSB1/usbshare/raw-files
state: present
state: mounted
fstype: nfs
- name: Install ngrok

6
supporting-scripts/site.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
#keep adding dirname's to go up more directories.
project_dir="$(dirname $( dirname $(readlink -f ${BASH_SOURCE[0]})))"
#ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ${project_dir}/hosts ${project_dir}/playbooks/lxc-test.yml
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ${project_dir}/hosts ${project_dir}/playbooks/kvm.yml
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ${project_dir}/hosts ${project_dir}/playbooks/site.yml