diff --git a/.gitignore b/.gitignore index c50648de..9c918dba 100644 --- a/.gitignore +++ b/.gitignore @@ -34,9 +34,13 @@ celery*.log resources_compiled.py # bootstrap +bootstrap/playbooks/*.retry bootstrap/packer_cache +bootstrap/output-qemu bootstrap/trusty64 bootstrap/solar-master.box +bootstrap/solar-master-centos-virtualbox.box +bootstrap/solar-master-centos-libvirt.box vagrant-settings.yaml .solar_cli_uids diff --git a/Vagrantfile b/Vagrantfile index 4f06b5c8..b4f49e0e 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -53,8 +53,14 @@ def ansible_playbook_command(filename, args=[]) "ansible-playbook -v -i \"localhost,\" -c local /vagrant/bootstrap/playbooks/#{filename} #{args.join ' '}" end +def shell_script(filename, env=[], args=[]) + "/bin/bash -c \"#{env.join ' '} #{filename} #{args.join ' '} 2>/dev/null\"" +end + solar_script = ansible_playbook_command("solar.yaml") solar_agent_script = ansible_playbook_command("solar-agent.yaml") +# NOTE(bogdando) w/a for a centos7 issue +fix_six = shell_script("/vagrant/bootstrap/playbooks/fix_centos7_six.sh") master_pxe = ansible_playbook_command("pxe.yaml") @@ -64,6 +70,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = MASTER_IMAGE config.vm.box_version = MASTER_IMAGE_VERSION + config.vm.provision "shell", inline: fix_six, privileged: true config.vm.provision "shell", inline: solar_script, privileged: true, env: {"SOLAR_DB_BACKEND": SOLAR_DB_BACKEND} config.vm.provision "shell", inline: master_pxe, privileged: true unless PREPROVISIONED config.vm.provision "file", source: "~/.vagrant.d/insecure_private_key", destination: "/vagrant/tmp/keys/ssh_private" @@ -120,6 +127,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.host_name = "solar-dev#{index}" if PREPROVISIONED + config.vm.provision "shell", inline: fix_six, privileged: true config.vm.provision "shell", inline: solar_agent_script, privileged: true #TODO(bogdando) figure out how to configure multiple interfaces when was not PREPROVISIONED ind = 0 diff --git a/bootstrap/http/ks.cfg b/bootstrap/http/ks.cfg new file mode 100644 index 00000000..98e7f563 --- /dev/null +++ b/bootstrap/http/ks.cfg @@ -0,0 +1,60 @@ +install +url --url="http://mirror.centos.org/centos/7/os/x86_64/" +lang en_US.UTF-8 +keyboard --vckeymap=us --xlayouts='us' +timezone Europe/Berlin --isUtc +network --device=eth0 --bootproto=dhcp --activate +network --hostname=localhost.localdomain +firewall --enable --ssh +services --enabled=NetworkManager,sshd,chronyd +selinux --disabled +auth --enableshadow --passalgo=sha512 +rootpw vagrant +text +skipx +clearpart --all --initlabel +zerombr +autopart +bootloader --location=mbr +firstboot --disabled +reboot + +%packages --ignoremissing --excludedocs +@core +chrony +openssh-clients +openssh-server +sudo +%end + +%post +# disable unnecessary services +chkconfig acpid off +chkconfig auditd off +chkconfig blk-availability off +chkconfig bluetooth off +chkconfig certmonger off +chkconfig cpuspeed off +chkconfig cups off +chkconfig haldaemon off +chkconfig ip6tables off +chkconfig lvm2-monitor off +chkconfig messagebus off +chkconfig mdmonitor off +chkconfig rpcbind off +chkconfig rpcgssd off +chkconfig rpcidmapd off +chkconfig yum-updateonboot off + +# vagrant +groupadd vagrant -g 1001 +useradd vagrant -g vagrant -G wheel -u 1001 +echo "vagrant" | passwd --stdin vagrant + +# sudo +yum install -y sudo +echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant +sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers + +yum clean all +%end diff --git a/bootstrap/playbooks/build-main.yaml b/bootstrap/playbooks/build-main.yaml index f70899ba..10a39e06 100644 --- a/bootstrap/playbooks/build-main.yaml +++ b/bootstrap/playbooks/build-main.yaml @@ -7,19 +7,19 @@ ssh_ip_mask: "10.*.*.*" tasks: - include: centos/tasks/{{ item }}.yaml - when: lookup('env', 'OSTYPE') == "centos" + when: ansible_os_family == "RedHat" with_items: - - cloud_archive + - rho - base - puppet - docker - ssh_conf - include: ubuntu/tasks/{{ item }}.yaml - when: lookup('env', 'OSTYPE') == "ubuntu" + when: ansible_os_family == "Debian" with_items: - base - puppet - docker - - cloud_archive + - uca - ssh_conf diff --git a/bootstrap/playbooks/centos/files/cleanup.sh b/bootstrap/playbooks/centos/files/cleanup.sh index 02ddccdb..7ab3c4ee 100644 --- a/bootstrap/playbooks/centos/files/cleanup.sh +++ b/bootstrap/playbooks/centos/files/cleanup.sh @@ -1,69 +1,29 @@ -#!/bin/bash -eux +#!/bin/sh -eux +yum -y clean all -# TODO(bogdando) add centos7 support -exit 0 -CLEANUP_PAUSE=${CLEANUP_PAUSE:-0} -echo "==> Pausing for ${CLEANUP_PAUSE} seconds..." -sleep ${CLEANUP_PAUSE} +# Remove Virtualbox specific files +rm -rf /usr/src/vboxguest* /usr/src/virtualbox-ose-guest* +rm -rf *.iso *.iso.? /tmp/vbox /home/vagrant/.vbox_version -# Make sure udev does not block our network - http://6.ptmc.org/?p=164 -echo "==> Cleaning up udev rules" -rm -rf /dev/.udev/ -rm /lib/udev/rules.d/75-persistent-net-generator.rules -rm /etc/udev/rules.d/70-persistent-net.rules -mkdir /etc/udev/rules.d/70-persistent-net.rules - -echo "==> Cleaning up leftover dhcp leases" -# Ubuntu 10.04 -if [ -d "/var/lib/dhcp3" ]; then - rm /var/lib/dhcp3/* -fi -# Ubuntu 12.04 & 14.04 -if [ -d "/var/lib/dhcp" ]; then - rm /var/lib/dhcp/* -fi - -# Add delay to prevent "vagrant reload" from failing -echo "pre-up sleep 2" >> /etc/network/interfaces - -echo "==> Cleaning up tmp" -rm -rf /tmp/* - -# Cleanup apt cache -apt-get -y autoremove --purge -apt-get -y clean -apt-get -y autoclean - -echo "==> Installed packages" -dpkg --get-selections | grep -v deinstall - -# Remove Bash history -unset HISTFILE -rm -f /root/.bash_history -rm -f /home/vagrant/.bash_history - -# Clean up log files +# Cleanup log files find /var/log -type f | while read f; do echo -ne '' > $f; done; -echo "==> Clearing last login information" ->/var/log/lastlog ->/var/log/wtmp ->/var/log/btmp +rm -rf /usr/share/doc/* + +# remove interface persistent +rm -f /etc/udev/rules.d/70-persistent-net.rules + +for ifcfg in $(ls /etc/sysconfig/network-scripts/ifcfg-*) +do + bn=$(basename ${ifcfg}) + if [ "${bn}" != "ifcfg-lo" ] + then + sed -i '/^UUID/d' /etc/sysconfig/network-scripts/${bn} + sed -i '/^HWADDR/d' /etc/sysconfig/network-scripts/${bn} + fi +done if [ "${cleanup}" = "true" ] ; then - # Whiteout root - count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}') - let count-- - dd if=/dev/zero of=/tmp/whitespace bs=1024 count=$count - rm /tmp/whitespace - - # Whiteout /boot - count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}') - let count-- - dd if=/dev/zero of=/boot/whitespace bs=1024 count=$count - rm /boot/whitespace - - # Zero out the free space to save space in the final image dd if=/dev/zero of=/EMPTY bs=1M rm -f /EMPTY fi diff --git a/bootstrap/playbooks/centos/files/vagrant_fix_nfs.sh b/bootstrap/playbooks/centos/files/vagrant_fix_nfs.sh new file mode 100644 index 00000000..944a78c4 --- /dev/null +++ b/bootstrap/playbooks/centos/files/vagrant_fix_nfs.sh @@ -0,0 +1,10 @@ +#!/bin/sh -eux +# When the docker0 int is created too early, +# Vagrant picks a wrong IP for its NFS mount. +# W/a by making docker unit to wait for the varrant nfs share +cat <>/usr/lib/systemd/system/docker.service +[Service] +ExecStartPre=/usr/bin/grep -q vagrant /etc/mtab +RestartSec=5 +Restart=always +EOF diff --git a/bootstrap/playbooks/centos/tasks/docker.yaml b/bootstrap/playbooks/centos/tasks/docker.yaml index 46d47e59..0792ef18 100644 --- a/bootstrap/playbooks/centos/tasks/docker.yaml +++ b/bootstrap/playbooks/centos/tasks/docker.yaml @@ -6,6 +6,14 @@ - shell: curl -sSL https://get.docker.com/ | sudo sh when: docker_version | failed +# enable docker and socker activation, mask exit codes for the nested host OS docker case +- shell: systemctl start docker + ignore_errors: yes +- shell: systemctl enable docker + ignore_errors: yes +- shell: systemctl enable docker.socket + ignore_errors: yes + # pre download riak image - shell: docker pull solarproject/riak diff --git a/bootstrap/playbooks/centos/tasks/cloud_archive.yaml b/bootstrap/playbooks/centos/tasks/rho.yaml similarity index 100% rename from bootstrap/playbooks/centos/tasks/cloud_archive.yaml rename to bootstrap/playbooks/centos/tasks/rho.yaml diff --git a/bootstrap/playbooks/centos/tasks/worker.yaml b/bootstrap/playbooks/centos/tasks/worker.yaml new file mode 100644 index 00000000..ca5f6d12 --- /dev/null +++ b/bootstrap/playbooks/centos/tasks/worker.yaml @@ -0,0 +1,5 @@ +--- + +- copy: src=/vagrant/utils/solar-worker.service dest=/usr/lib/systemd/system/solar-worker.service +- shell: systemctl daemon-reload +- service: name=solar-worker state=started enabled=yes diff --git a/bootstrap/playbooks/centos/tasks/worker_upstart.yaml b/bootstrap/playbooks/centos/tasks/worker_upstart.yaml deleted file mode 100644 index 1964fe68..00000000 --- a/bootstrap/playbooks/centos/tasks/worker_upstart.yaml +++ /dev/null @@ -1,9 +0,0 @@ ---- - -# TODO(bogdando) for centos7, systemd -#- copy: src=/vagrant/utils/solar-worker-defaults dest=/etc/default/solar-worker -#- copy: src=/vagrant/utils/solar-worker.conf dest=/etc/init/solar-worker.conf -#- shell: stop solar-worker -# ignore_errors: yes -#- shell: start solar-worker -- shell: /bin/true diff --git a/bootstrap/playbooks/solar.yaml b/bootstrap/playbooks/solar.yaml index 0e791c39..3801f78c 100644 --- a/bootstrap/playbooks/solar.yaml +++ b/bootstrap/playbooks/solar.yaml @@ -11,9 +11,9 @@ - shell: pip install -e . chdir=/vagrant - shell: pip install git+git://github.com/Mirantis/solar-agent.git - include: centos/tasks/ssh_conf.yaml - when: lookup('env', 'OSTYPE') == "centos" + when: ansible_os_family == "RedHat" - include: ubuntu/tasks/ssh_conf.yaml - when: lookup('env', 'OSTYPE') == "ubuntu" + when: ansible_os_family == "Debian" - hosts: localhost tasks: @@ -68,7 +68,7 @@ # shared stuff for all databases - include: databases.yaml - - include: centos/tasks/worker_upstart.yaml - when: lookup('env', 'OSTYPE') == "centos" - - include: ubuntu/tasks/worker_upstart.yaml - when: lookup('env', 'OSTYPE') == "ubuntu" + - include: centos/tasks/worker.yaml + when: ansible_os_family == "RedHat" + - include: ubuntu/tasks/worker.yaml + when: ansible_os_family == "Debian" diff --git a/bootstrap/playbooks/ubuntu/tasks/cloud_archive.yaml b/bootstrap/playbooks/ubuntu/tasks/uca.yaml similarity index 100% rename from bootstrap/playbooks/ubuntu/tasks/cloud_archive.yaml rename to bootstrap/playbooks/ubuntu/tasks/uca.yaml diff --git a/bootstrap/playbooks/ubuntu/tasks/worker_upstart.yaml b/bootstrap/playbooks/ubuntu/tasks/worker.yaml similarity index 100% rename from bootstrap/playbooks/ubuntu/tasks/worker_upstart.yaml rename to bootstrap/playbooks/ubuntu/tasks/worker.yaml diff --git a/bootstrap/solar-master-centos-docker.json b/bootstrap/solar-master-centos-docker.json index 94f61ae7..0a404f63 100644 --- a/bootstrap/solar-master-centos-docker.json +++ b/bootstrap/solar-master-centos-docker.json @@ -59,7 +59,6 @@ ]}, { "type": "shell", "environment_vars": [ - "OSTYPE=centos", "CM={{user `cm`}}", "CM_VERSION={{user `cm_version`}}", "CLEANUP_PAUSE={{user `cleanup_pause`}}", @@ -84,7 +83,6 @@ }, { "type": "shell", "environment_vars": [ - "OSTYPE=centos", "CM=ansible", "CM_VERSION=latest" ], @@ -94,12 +92,10 @@ "type": "ansible-local", "playbook_dir": "playbooks", "playbook_file": "playbooks/build-main.yaml", - "extra_arguments": ["--verbose"], - "command": "OSTYPE=centos ansible-playbook" + "extra_arguments": ["--verbose"] }, { "type": "shell", "environment_vars": [ - "OSTYPE=centos", "cleanup={{user `cleanup`}}" ], "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'", diff --git a/bootstrap/solar-master-centos.json b/bootstrap/solar-master-centos.json new file mode 100644 index 00000000..3bc7ac3e --- /dev/null +++ b/bootstrap/solar-master-centos.json @@ -0,0 +1,164 @@ +{ + "variables": { + "cm": "puppet", + "cm_version": "latest", + "cleanup_pause": "", + "headless": "{{env `headless`}}", + "update": "true", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "install_vagrant_key": "true", + "http_proxy": "{{env `http_proxy`}}", + "https_proxy": "{{env `https_proxy`}}", + "ftp_proxy": "{{env `ftp_proxy`}}", + "rsync_proxy": "{{env `rsync_proxy`}}", + "no_proxy": "{{env `no_proxy`}}", + "iso_url": "http://centos1.hti.pl/7/isos/x86_64/CentOS-7-x86_64-NetInstall-1511.iso", + "iso_checksum": "99d305fa40ec9e28ef8450c3bcc45f85", + "disk_size": "4500", + "mem_size": "512", + "vcpu_num": "1", + "cleanup": "true", + "ansible_config_path": "/etc/ansible", + "ansible_config_file": "ansible.cfg", + "ansible_log_file": "/var/tmp/ansible.log" + }, + "builders": [{ + "vm_name": "centos7", + "type": "qemu", + "format": "qcow2", + "accelerator": "kvm", + "http_directory": "http", + "iso_url": "{{ user `iso_url` }}", + "iso_checksum": "{{ user `iso_checksum` }}", + "iso_checksum_type": "md5", + "ssh_username": "{{ user `ssh_username` }}", + "ssh_password": "{{ user `ssh_password` }}", + "ssh_wait_timeout": "10000s", + "headless": "{{ user `headless` }}", + "boot_wait": "30s", + "boot_command": [ + " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" + ], + "shutdown_command": "echo 'vagrant' | sudo -S /sbin/halt -h -p", + "disk_size": "{{ user `disk_size`}}", + "qemuargs": [ + [ + "-m", + "{{user `mem_size`}}M" + ], + [ + "-smp", + "{{ user `vcpu_num`}}" + ] + ] + }, + { + "vm_name": "centos7", + "type": "virtualbox-iso", + "http_directory": "http", + "iso_url": "{{ user `iso_url` }}", + "iso_checksum": "{{ user `iso_checksum` }}", + "iso_checksum_type": "md5", + "guest_os_type": "RedHat_64", + "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", + "virtualbox_version_file": ".vbox_version", + "headless": "{{ user `headless` }}", + "ssh_username": "{{ user `ssh_username` }}", + "ssh_password": "{{ user `ssh_password` }}", + "ssh_wait_timeout": "10000s", + "boot_wait": "30s", + "boot_command": [ + " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" + ], + "shutdown_command": "echo 'vagrant' | sudo -S /sbin/halt -h -p", + "disk_size": "{{ user `disk_size`}}", + "vboxmanage": [ + ["modifyvm", "{{.Name}}", "--memory", "{{ user `mem_size`}}"], + ["modifyvm", "{{.Name}}", "--cpus", "{{ user `vcpu_num`}}"] + ] + }], + "provisioners": [{ + "type": "shell", + "execute_command": "echo '{{user `ssh_password`}}' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'", + "inline": [ + "echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers" + ]}, { + "type": "shell", + "inline": ["sudo mkdir -p {{ user `ansible_config_path` }}"] + }, { + "type": "shell", + "inline": [ + "touch /tmp/ansible.cfg", + "sudo mv /tmp/ansible.cfg {{ user `ansible_config_path` }}/{{ user `ansible_config_file` }}", + "sudo echo '[defaults]' >> {{ user `ansible_config_path` }}/{{ user `ansible_config_file` }}", + "sudo echo 'log_path = {{ user `ansible_log_file` }}' >> {{ user `ansible_config_path` }}/{{ user `ansible_config_file` }}", + "sudo touch {{ user `ansible_log_file` }}", + "sudo chmod 666 {{ user `ansible_log_file` }}" + ]}, { + "type": "shell", + "environment_vars": [ + "CM={{user `cm`}}", + "CM_VERSION={{user `cm_version`}}", + "CLEANUP_PAUSE={{user `cleanup_pause`}}", + "UPDATE={{user `update`}}", + "INSTALL_VAGRANT_KEY={{user `install_vagrant_key`}}", + "SSH_USERNAME={{user `ssh_username`}}", + "SSH_PASSWORD={{user `ssh_password`}}", + "http_proxy={{user `http_proxy`}}", + "https_proxy={{user `https_proxy`}}", + "ftp_proxy={{user `ftp_proxy`}}", + "rsync_proxy={{user `rsync_proxy`}}", + "no_proxy={{user `no_proxy`}}" + ], + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'", + "scripts": [ + "playbooks/centos/files/update.sh", + "playbooks/centos/files/tools.sh", + "playbooks/centos/files/cmtool.sh", + "playbooks/centos/files/vagrant.sh", + "playbooks/centos/files/sshd.sh" + ] + }, { + "type": "shell", + "environment_vars": [ + "CM=ansible", + "CM_VERSION=latest" + ], + "script": "playbooks/centos/files/cmtool.sh", + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'" + }, { + "type": "ansible-local", + "playbook_dir": "playbooks", + "playbook_file": "playbooks/build-main.yaml", + "extra_arguments": ["--verbose"] + }, { + "type": "shell", + "environment_vars": [ + "cleanup={{user `cleanup`}}" + ], + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'", + "scripts": [ + "playbooks/centos/files/vagrant_fix_nfs.sh", + "playbooks/centos/files/vmtool.sh", + "playbooks/centos/files/minimize.sh", + "playbooks/centos/files/cleanup.sh" + ] + }], + "post-processors": [ + [ + { + "type": "vagrant", + "keep_input_artifact": true, + "only": ["qemu"], + "output": "solar-master-centos-libvirt.box" + }, + { + "type": "vagrant", + "keep_input_artifact": false, + "only": ["virtualbox-iso"], + "output": "solar-master-centos-virtualbox.box" + } + ] + ] +} diff --git a/bootstrap/solar-master-ubuntu-docker.json b/bootstrap/solar-master-ubuntu-docker.json index ea519c4f..8ae63e5b 100644 --- a/bootstrap/solar-master-ubuntu-docker.json +++ b/bootstrap/solar-master-ubuntu-docker.json @@ -59,7 +59,6 @@ ]}, { "type": "shell", "environment_vars": [ - "OSTYPE=ubuntu", "CM={{user `cm`}}", "CM_VERSION={{user `cm_version`}}", "CLEANUP_PAUSE={{user `cleanup_pause`}}", @@ -84,7 +83,6 @@ }, { "type": "shell", "environment_vars": [ - "OSTYPE=ubuntu", "CM=ansible", "CM_VERSION=latest" ], @@ -94,12 +92,10 @@ "type": "ansible-local", "playbook_dir": "playbooks", "playbook_file": "playbooks/build-main.yaml", - "extra_arguments": ["--verbose"], - "command": "OSTYPE=ubuntu ansible-playbook" + "extra_arguments": ["--verbose"] }, { "type": "shell", "environment_vars": [ - "OSTYPE=ubuntu", "cleanup={{user `cleanup`}}" ], "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'", diff --git a/bootstrap/solar-master.json b/bootstrap/solar-master.json index 6bcdc855..6cf8dad9 100644 --- a/bootstrap/solar-master.json +++ b/bootstrap/solar-master.json @@ -127,7 +127,6 @@ ]}, { "type": "shell", "environment_vars": [ - "OSTYPE=ubuntu", "CM={{user `cm`}}", "CM_VERSION={{user `cm_version`}}", "CLEANUP_PAUSE={{user `cleanup_pause`}}", @@ -152,7 +151,6 @@ }, { "type": "shell", "environment_vars": [ - "OSTYPE=ubuntu", "CM=ansible", "CM_VERSION=latest" ], @@ -162,12 +160,10 @@ "type": "ansible-local", "playbook_dir": "playbooks", "playbook_file": "playbooks/build-main.yaml", - "extra_arguments": ["--verbose"], - "command": "OSTYPE=ubuntu ansible-playbook" + "extra_arguments": ["--verbose"] }, { "type": "shell", "environment_vars": [ - "OSTYPE=ubuntu", "cleanup={{user `cleanup`}}" ], "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'", diff --git a/utils/solar-worker.service b/utils/solar-worker.service index e95b694e..b9bb248f 100644 --- a/utils/solar-worker.service +++ b/utils/solar-worker.service @@ -4,7 +4,7 @@ After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=simple -ExecStart=solar-worker +ExecStart=/usr/bin/solar-worker PrivateTmp=true KillSignal=SIGQUIT Restart=always