create bootstrap_vms role to run vagrant file on host, creating managed vms (dkhost03 and dkhost04)

This commit is contained in:
2017-06-06 09:31:12 -04:00
parent 7374d7767b
commit a05d635641
18 changed files with 275 additions and 71 deletions

View File

@@ -2,7 +2,7 @@
# playbook for home02 # playbook for home02
- hosts: dkhost02 - hosts: dkhost
remote_user: ansible remote_user: ansible
gather_facts: yes gather_facts: yes
become: true become: true
@@ -62,7 +62,7 @@
# - Datadog.datadog # - Datadog.datadog
- dockerhost - dockerhost
- geerlingguy.nginx - geerlingguy.nginx
# - certbot - certbot
# - docker_registry # - docker_registry
# - docker_graylog # - docker_graylog

View File

@@ -10,11 +10,12 @@
vars: vars:
cluster: cluster:
- cubox-i.xai-corp.net - cubox-i.xai-corp.net
# - home - home
mountpoints: mountpoints:
- /data/glusterfs/vmshares/brick1 - /data/glusterfs/vmshares/brick1
- /data/glusterfs/gitea/brick1 - /data/glusterfs/gitea/brick1
- /data/glusterfs/jenkins/brick1 - /data/glusterfs/jenkins/brick1
- /data/glusterfs/tmp/brick1
volumes: volumes:
vmshares: vmshares:
- /data/glusterfs/vmshares/brick1/brick - /data/glusterfs/vmshares/brick1/brick
@@ -22,6 +23,8 @@
- /data/glusterfs/gitea/brick1/brick - /data/glusterfs/gitea/brick1/brick
jenkins: jenkins:
- /data/glusterfs/jenkins/brick1/brick - /data/glusterfs/jenkins/brick1/brick
# tmp:
# - /data/glusterfs/tmp/brick1/brick
roles: roles:
- glusterfs - glusterfs

View File

@@ -7,28 +7,35 @@
become: true become: true
vars: vars:
datadog_api_key: ca0faf176c4aedd4f547ed7cf85615eb cleanup:
datadog_checks: packages:
system: - git
init_config: [] cron:
instances: [] - { name: "zoneedit", file: "zoneedit" }
disk: # datadog_api_key: ca0faf176c4aedd4f547ed7cf85615eb
init_config: # datadog_checks:
instances: # system:
- use_mount: yes # init_config: []
excluded_filesystems: # instances: []
- sysfs # disk:
- cgroup # init_config:
- tracefs # instances:
- debugfs # - use_mount: yes
- proc # excluded_filesystems:
- securityfs # - sysfs
excluded_mountpoint_re: /[media/richard|run/user].* # - cgroup
# - tracefs
# - debugfs
# - proc
# - securityfs
# excluded_mountpoint_re: /[media/richard|run/user].*
roles: roles:
# - Datadog.datadog # - Datadog.datadog
# - dockerhost # - dockerhost
- dynamic-ip # - dynamic-ip
- bootstrap_vms
- cleanup
post_tasks: post_tasks:

View File

@@ -2,35 +2,41 @@
# playbook for home02 # playbook for home02
- hosts: home2 - hosts: home02
remote_user: ansible remote_user: ansible
gather_facts: yes gather_facts: yes
become: true become: true
vars: vars:
datadog_api_key: ca0faf176c4aedd4f547ed7cf85615eb cleanup:
datadog_checks: packages:
system: - git
init_config: [] cron: []
instances: [] # datadog_api_key: ca0faf176c4aedd4f547ed7cf85615eb
disk: # datadog_checks:
init_config: # system:
instances: # init_config: []
- use_mount: yes # instances: []
excluded_filesystems: # disk:
- sysfs # init_config:
- cgroup # instances:
- tracefs # - use_mount: yes
- debugfs # excluded_filesystems:
- proc # - sysfs
- securityfs # - cgroup
excluded_mountpoint_re: /[media/richard|run/user].* # - tracefs
# - debugfs
# - proc
# - securityfs
# excluded_mountpoint_re: /[media/richard|run/user].*
roles: roles:
- Datadog.datadog # - Datadog.datadog
- ns.xai-corp.net # - ns.xai-corp.net
- td-agent-bit # - td-agent-bit
- dynamic-ip
- cleanup
post_tasks: post_tasks:
# - name: check service is up # - name: check service is up

View File

@@ -43,6 +43,11 @@
- name: Creates .ssh directory - name: Creates .ssh directory
file: path=~/.ssh state=directory mode=600 file: path=~/.ssh state=directory mode=600
- name: remove ubuntu user if it exists
command: userdel -rf ubuntu
args:
removes: /home/ubuntu/.bashrc
- debug: var=ansible_os_family - debug: var=ansible_os_family
roles: roles:

View File

@@ -0,0 +1,4 @@
---
#default variables for boostrap_vms
vagrant_folder: "/opt/home.xai-corp.net/vm_config"

76
roles/bootstrap_vms/files/Vagrantfile vendored Normal file
View File

@@ -0,0 +1,76 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
BASE_BOX = "ubuntu/xenial64"
BRIDGE_NET = "enp3s0"
$script = <<SCRIPT
echo I am provisioning...
sudo adduser --home /home/ansible --shell /bin/bash --uid 1001 --disabled-password ansible
sudo mkdir -p /home/ansible/.ssh
sudo cat /etc/sudoers
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAmJSdmj03d4fnZUuRByevPDNiReEk1fRL+7F9WPCo5zn+r5Oj84HXxd4P03DNXeGSBYmUAnsTqYEGdkjkpSrKfMm9bv8amL7hUC+Mzb+wOmXmyX1cw/SearYCBQRCz1s5p7I9+PO7XWaC0VJ99LUm1Bp4JM149U5X0Y3M2j2XV+0= RSA-1024" | sudo tee -a /home/ansible/.ssh/authorized_keys
sudo chmod 600 /home/ansible/.ssh/authorized_keys
sudo chmod 700 /home/ansible/.ssh
sudo chown -R ansible /home/ansible
sudo echo "ansible ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
sudo apt -y update && sudo apt install -y python-minimal
date > /etc/vagrant_provisioned_at
SCRIPT
Vagrant.configure("2") do |config|
config.vm.define "dkhost03" do |dkhost03|
dkhost03.vm.hostname = "dkhost03"
dkhost03.vm.box = BASE_BOX
dkhost03.vm.box_check_update = true
dkhost03.vm.network "public_network", bridge: BRIDGE_NET
dkhost03.vm.synced_folder '.', '/vagrant', disabled: true
dkhost03.vm.provision "shell", inline: $script
dkhost03.vm.provider "virtualbox" do |vb|
vb.name = "dkhost03"
vb.gui = false
vb.memory = "2048"
vb.cpus = 2
#vb.customize ["modifyvm", :id, "--autostart-enabled", "on"]
#vb.customize ["modifyvm", :id, "--autostart-delay", "30"]
vb.customize ["modifyvm", :id, "--macaddress2", "08002794035A"]
end
end
config.vm.define "dkhost04" do |dkhost04|
dkhost04.vm.hostname = "dkhost04"
dkhost04.vm.box = BASE_BOX
dkhost04.vm.box_check_update = true
dkhost04.vm.network "public_network", bridge: BRIDGE_NET
dkhost04.vm.synced_folder '.', '/vagrant', disabled: true
dkhost04.vm.provision "shell", inline: $script
dkhost04.vm.provider "virtualbox" do |vb|
vb.name = "dkhost04"
vb.gui = false
vb.memory = "1024"
vb.cpus = 2
#vb.customize ["modifyvm", :id, "--autostart-enabled", "on"]
#vb.customize ["modifyvm", :id, "--autostart-delay", "30"]
vb.customize ["modifyvm", :id, "--macaddress2", "080027FD5A0E"]
end
end
end

View File

@@ -0,0 +1,9 @@
---
# meta/main.yml
# define dependancies here
# dependencies:
# - { role: geerlingguy.java }
dependencies:
- { role: vagrant }

View File

@@ -0,0 +1,32 @@
---
# bootstrap vms on host machine
# install required system packages
- name: install system packages
apt:
state: present
name: "{{item}}"
update_cache: yes
with_items: []
# copy across vagrant file
- name: create target folder
file:
state: directory
dest: "{{ vagrant_folder }}"
- name: copy vagrant file
copy:
src: Vagrantfile
dest: "{{ vagrant_folder }}/Vagrantfile"
# update and run vagrant boxes
- name: update vagrant box
command: vagrant box update
args:
chdir: "{{vagrant_folder}}"
- name: vagrant up
command: vagrant up
args:
chdir: "{{vagrant_folder}}"

View File

@@ -0,0 +1,6 @@
---
# defaults for cleanup
cleanup:
cron: []
packages: []

View File

@@ -0,0 +1,18 @@
---
# cleanup/tasks/main.yml
# removes packages and cron jobs
- name: remove packages
apt:
state: absent
name: "{{item}}"
update_cache: yes
with_items: "{{ cleanup.packages }}"
- name: remove cronjob
cron:
state: absent
name: "{{ item.name }}"
cron_file: "{{ item.file }}"
with_items: "{{ cleanup.cron }}"

View File

@@ -29,6 +29,18 @@
name: "{{ item.key }}" name: "{{ item.key }}"
brick: '{{ item.value | join(",")}}' brick: '{{ item.value | join(",")}}'
rebalance: no rebalance: no
replicas: 2
cluster: "{{cluster}}" cluster: "{{cluster}}"
with_dict: "{{volumes}}" with_dict: "{{volumes}}"
run_once: true run_once: true
# manage volumes
- name: create tmp gluster volumes
gluster_volume:
state: present
name: "tmp"
brick: '/data/glusterfs/tmp/brick1/brick'
rebalance: no
replicas: 2
cluster: "{{cluster}}"
run_once: true

View File

@@ -0,0 +1,9 @@
---
# meta/main.yml
# define dependancies here
# dependencies:
# - { role: geerlingguy.java }
dependencies:
- { role: vagrant }

View File

@@ -11,27 +11,6 @@
- git - git
- virtualbox - virtualbox
# install vagrant
- stat: path=/usr/bin/vagrant
register: vagrant_exe
- name: download vagrant package
get_url:
dest: "{{ vagrant_installer_path }}"
url: "{{ vagrant_installer_url }}"
when: vagrant_exe.stat.exists == False
- name: install vagrant deb from download
apt:
deb: "{{ vagrant_installer_path }}"
when: vagrant_exe.stat.exists == False
- name: remove vagrant installer
file:
state: absent
path: "{{ vagrant_installer_path }}"
# install kubectl # install kubectl
- stat: path="{{kubernetes_kubectl_path}}" - stat: path="{{kubernetes_kubectl_path}}"
register: kubectl_exe register: kubectl_exe

View File

@@ -8,10 +8,10 @@ $TTL 2d
1d ) ;minimum 1d ) ;minimum
xai-corp.net. IN NS ns.xai-corp.net. xai-corp.net. IN NS ns.xai-corp.net.
xai-corp.net. IN A 208.94.116.179 ;xai-corp.net. IN A 208.94.116.179
xai-corp.net. IN A 208.94.116.21 ;xai-corp.net. IN A 208.94.116.21
xai-corp.net. IN A 208.94.117.26 ;xai-corp.net. IN A 208.94.117.26
www.xai-corp.net. IN A 208.94.116.179 ;www.xai-corp.net. IN A 208.94.116.179
www.xai-corp.net. IN A 208.94.116.21 ;www.xai-corp.net. IN A 208.94.116.21
www.xai-corp.net. IN A 208.94.117.26 ;www.xai-corp.net. IN A 208.94.117.26

View File

@@ -39,6 +39,6 @@ logs IN A 192.168.2.42
dkhost02 IN A 192.168.2.43 dkhost02 IN A 192.168.2.43
fs IN A 192.168.2.43 fs IN A 192.168.2.43
git IN A 192.168.2.43 git IN A 192.168.2.43
dkui IN A 192.168.2.41 dkui IN A 192.168.2.43
jenkins IN A 192.168.2.41 jenkins IN A 192.168.2.43

View File

@@ -0,0 +1,5 @@
---
#default values
vagrant_installer_url: https://releases.hashicorp.com/vagrant/1.8.6/vagrant_1.8.6_x86_64.deb
vagrant_installer_path: /tmp/vagrant_installer.deb

View File

@@ -0,0 +1,33 @@
---
# main tasks for installing vagrant
# install required system packages
- name: install system packages
apt:
state: present
name: "{{item}}"
update_cache: yes
with_items:
- git
- virtualbox
# install vagrant
- stat: path=/usr/bin/vagrant
register: vagrant_exe
- name: download vagrant package
get_url:
dest: "{{ vagrant_installer_path }}"
url: "{{ vagrant_installer_url }}"
when: vagrant_exe.stat.exists == False
- name: install vagrant deb from download
apt:
deb: "{{ vagrant_installer_path }}"
when: vagrant_exe.stat.exists == False
- name: remove vagrant installer
file:
state: absent
path: "{{ vagrant_installer_path }}"