diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b844b14..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -Gemfile.lock diff --git a/CHANGELOG b/CHANGELOG index 705e1e4..7b459c0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,41 @@ CHANGELOG ========= +2.6: 2017-07-14 +--------------- +New Features: +- New kvm-control job: "KVM: Delete all guests". +- New kvm-control job: "Docker: Restart chef-rundeck". +- Can re-fetch the Knife admin keys if needed. +- Rundeck-cli now usable by the Linux user that installed Mission_Control. +- Using job "Source: Add Cloud Image or ISO" to get the first source image. +- Using Rundeck "Source: Add Cloud Image or ISO" job to fetch first source image instead of separate script. + +Updates: +- Merged chef-server-control and kvm-control_with-Chef projects into kvm-control. +- Load Rundeck jobs everytime the install script runs. +- Use new XML format for Rundeck jobs. +- Don't use 'bundle_install' method anymore. Use 'gem install' instead. +- Renamed 'third_octet' by 'third_byte'. +- Cleanup the use of the 'check_vars' method. +- Took out duplicate jobs in chef-rundeck_jobs.xml.erb. +- Updated get_ip_host logic. +- Use libvirt gem for KVM jobs. +- Don't need to get mysql-connector-java-5.1.40.tar.gz anymore. +- Don't use sudo command everywhere. +- Updated README. + +Fixes: +- Don't restart Rundeck while installing KVM. + +Removed: +- scripts/create_rd_projects.sh +- kvm/templates/get_images.rb.erb +- kvm/get_first_cloud_image.rb +- docker/template/rundeck_jobs-chef.xml.erb +- scripts/templates/Gemfile.erb +- scripts/get_interface_ip.rb + 2.5: 2017-06-16 --------------- New Features: @@ -10,7 +45,7 @@ New Features: - Using chef-rundeck in a container. Updates: -- Using newer Docker image (v2.3). +- Using newer chef-server Docker image (v2.3). - Shell and Ruby lint. - Output color for the bash scripts. - New env variable for libvirt. diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 018aa6b..0000000 --- a/Gemfile +++ /dev/null @@ -1,4 +0,0 @@ -source 'https://rubygems.org' - -gem 'colorize' -gem 'json' diff --git a/README.md b/README.md index f3c5f1a..7a19282 100644 --- a/README.md +++ b/README.md @@ -1,91 +1,90 @@ -#Mission_Control +# Mission_Control -##Description +## Description Mission_Control is a set of Rundeck projects that lets you `create / start / shutdown / destroy` virtual machines and containers. -##Installation +## Installation -You will need to execute the `install` script to install all the required packages, gems and lay down the configuration files. +First, edit the `vars` file with your parameters. Then, you will need to execute the `install` script to install all the required packages, gems and lay down the configuration files. +```bash + cbuisson@server:~/mission_control$ ./install +``` +To update the current configuration, edit the `vars` file and execute the `install` script again. The script can be run anytime. - ./install +## Environment -**Variables:** You can edit the `vars` file to reflect your current environment or what you want. You can paste your SSH public keys here. +Mission_Control has been developed for a **brand new** install of **Ubuntu Xenial 16.04 LTS**. -The install process will display a menu where you can choose to install any feature that you want. +## Project: *kvm-control* -##Environment +Launch a new personalized KVM guest with: + - SSH public keys importation + - Automatic DNS entry creation + - Static IP assignment + - VNC accessibility + - Chef-client installed and configured -Mission_Control has been developed for **Ubuntu Xenial 16.04 LTS**. +kvm-control will launch the KVM guests with a fully qualified domain name `.local`. Bind9 will be installed/used by default to dynamically manage the DNS A and PTR records. -#*kvm-control* +kvm-control was designed to work with Class C IPs. The netmask is hard coded to: **255.255.255.0**. -You can choose to start a new virtual machine with an ISO or an Ubuntu Cloud image. +You can also choose to start a new virtual machine with an ISO or an Ubuntu Cloud image. When an Ubuntu Cloud image is used to launch a new instance, the KVM guest will get a static IP. ISO's on the other hand, will get a DHCP IP. -When an Ubuntu Cloud image is used to launch a new instance, the vm will get a static IP. ISO's on the other hand, will get a DHCP ip. +### Network setup (Floating IP / NAT IP) -###Network types: -*Netmask*: kvm-control was designed to work with Class C IPs, therefore the netmask is hard coded to: 255.255.255.0 +You can choose to assign a floating IP (public address accessible by external servers on the same local network) or a NAT IP (private address accessible by the hypervisor only) when launching a new KVM guest in Rundeck. The guest will be assigned a static IP and a VNC port. -*Fqdn*: kvm-control will launch the KVM guests with a fully qualified domain name `.local`. Bind9 will be installed by default to dynamically manage the DNS A and PTR records. See `vars` file. +Deleting the KVM guest will release both the IP (floating or NAT) and the VNC port. -####Floating IPs +### Floating IPs -You will need to edit the `vars` file and add: +You will need to edit the `vars` file and already have created a Linux bridge interface: - - The interface out (**Must be br0** if using floating static IPs!) - - A backend type (*MySQL or PostgreSQL*) + - Interface out (**Must be named**: `br0`!) - Start IP (*i.e 192.168.0.1*) - End IP (*i.e 192.168.0.100*) - Gateway IP (*i.e 192.168.0.254*) -Mission_Control will assign floating IPs to the KVM guests. Those floating IPs should be able to reach the hypervisor's IP and the gateway. You need to specify a floating IP range for the guests and a gateway to route out. - -**NAT IPs**: - -By default Libvirt will install a new interface `virbr0` that will be managed by a DNSmasq process. DNSmasq will assign IPs to the new KVM guest with DHCP. The default range is: - -- *192.168.122.2 to 192.168.122.254* +The kvm-control's jobs will assign floating IPs to the KVM guests. These floating IPs should be able to reach the hypervisor and the gateway IPs. -You can choose to assign a floating IP or a NAT IP when launching a new guest in Rundeck (i.e `Launch KVM guest`). Either way, the guest will be assigned a reserve static IP and a VNC port. +### NAT IPs -Deleting the KVM guest will release both the IP (floating or NAT) and the VNC port. - -#*chef_server-control* +By default, Libvirt will configure a new interface (`virbr0`) that will be managed by a DNSmasq process. DNSmasq will assign IPs to the new KVM guest with DHCP. The default range is from **192.168.122.2** to **192.168.122.254**. -This is a Docker container that come with Chef Server 11 already installed. Mission_Control will download and launch this container if you want to. It will also grab the Knife admin keys and configure the Rundeck user to be able to use Knife. +### Chef-Server -Also, the gem `chef-rundeck` will be installed and configure. This allows Rundeck to display Chef nodes directly in the "Nodes" panel. You can run command directly to the Chef nodes via Rundeck. +You can optionally bootstrap the KVM guests to a Chef-Server at launch time. +In order to use this feature, select the "Docker Chef container" option while running the `install` script. This option will appears after the installation of `kvm-control`. -#*docker-control* +Mission_Control will start the two following Docker instances: -You can manage Docker containers and images with this project. +**Chef-Server**: Comes with Chef Server 12 already installed and configured. Mission_Control will also grab the Knife admin keys and configure both your current user and the Rundeck user to be able to use the Knife command. -Assumptions ------------ +**Chef-Rundeck**: Allows Rundeck to display the Chef client nodes directly in the "Nodes" tab. Once visible, you can run commands directly to the Chef client nodes from the Rundeck UI. -###kvm-control: +### Notes - - VMs will reach the internet trough the hypervisor via `br0` if floating IP selected. While using NAT, `virbr0` will be used. + - KVM guests will reach the internet trough the hypervisor via `br0` when the floating IPs are selected. - If a guest is launched with the NAT option, `virbr0` (192.168.122.1) will be used to route out. -###chef_server-control: - - - The Docker Chef_Server will be accessible via HTTPS:$CHEF_PORT. + - The Chef-Server container will be accessible from the hypervisor via: HTTPS://$CHEF_SERVER_CONTAINER_NAME:$CHEF_PORT. -Requirements ------------ - -###KVM +### KVM Requirements The hypervisor should have `Virtual Technology` enabled. You can test this prior the installation by running: - - ubuntu@cbuisson:~$ egrep -c '(vmx|svm)' /proc/cpuinfo +```bash + cbuisson@server:~$ egrep -c '(vmx|svm)' /proc/cpuinfo #Anything but 0 is good. - +``` And after the installation: - - ubuntu@cbuisson:~$ kvm-ok +```bash + cbuisson@server:~$ kvm-ok INFO: /dev/kvm exists KVM acceleration can be used +``` + +## Project: *docker-control* + +You can manage Docker containers and images with this project. diff --git a/docker/rundeck_jobs.xml b/docker/rundeck_jobs.xml index 78a1f44..e166402 100644 --- a/docker/rundeck_jobs.xml +++ b/docker/rundeck_jobs.xml @@ -1,40 +1,47 @@ - 96a978e4-2e96-4b23-89c0-ff6d1d8ddad6 + Stop and delete all Docker containers! + true + 09bfb40a-26b8-4c29-b342-9391bfea40b6 INFO + Delete all containers + true + true - + + + + - Stop all Docker containers. - Stop all containers - - docker-control - - 96a978e4-2e96-4b23-89c0-ff6d1d8ddad6 + 09bfb40a-26b8-4c29-b342-9391bfea40b6 - f111f4ca-4ba4-4945-be86-bfe5b47a1114 + Delete all Docker images. + true + e08a615e-9aac-4913-a831-468cd7fc7e0d INFO + Delete all images + true + true - + - Delete all Docker images. - Delete all images - - docker-control - - f111f4ca-4ba4-4945-be86-bfe5b47a1114 + e08a615e-9aac-4913-a831-468cd7fc7e0d - 416d8f91-f0c2-4603-9a70-1ad91242a51d + List them all! + true + 51726770-d6e5-4fbb-9287-b77461badfbc INFO + List all containers + true + true - - - - - +docker ps -a]]> + - Stop and delete all Docker containers! - Delete all containers - - docker-control - - 416d8f91-f0c2-4603-9a70-1ad91242a51d + 51726770-d6e5-4fbb-9287-b77461badfbc - cd820882-15bf-4f30-b7b3-ec4e60dd548a + List all local images + true + 0a718e02-5189-4dbf-8e19-300108561a87 INFO + List all images + true + true - +docker images]]> + - List them all! - List all containers - - docker-control - - cd820882-15bf-4f30-b7b3-ec4e60dd548a + 0a718e02-5189-4dbf-8e19-300108561a87 - bbf54c33-fc96-48eb-a61e-f887917e6abe + List only the running containers + true + 3d19b229-ebef-4fc7-9904-75efaa14621b INFO + List all running containers + true + true - + - List only the running containers - List all running containers - - docker-control - - bbf54c33-fc96-48eb-a61e-f887917e6abe + 3d19b229-ebef-4fc7-9904-75efaa14621b - 0ad015fb-9883-4f11-850e-effd25517d37 + Stop all Docker containers. + true + 86a67182-ffbf-4f17-9654-aa253f0e5355 INFO + Stop all containers + true + true - - + sleep 5 + system("docker ps -a") + puts "\nAll the Docker containers have been stopped!" +end]]> + - List all local images - List all images - - docker-control - - 0ad015fb-9883-4f11-850e-effd25517d37 + 86a67182-ffbf-4f17-9654-aa253f0e5355 diff --git a/docker/template/rundeck_jobs-chef.xml.erb b/docker/template/rundeck_jobs-chef.xml.erb deleted file mode 100644 index fd47f7d..0000000 --- a/docker/template/rundeck_jobs-chef.xml.erb +++ /dev/null @@ -1,81 +0,0 @@ - - - a37ea70a-b691-4fad-a78e-f049000850eb - INFO - - - - - - - Find <%= CHEF_SERVER_CONTAINER_NAME %> image and container ID then delete all the files. - Remove <%= CHEF_SERVER_CONTAINER_NAME %> container - - chef_server-control - - a37ea70a-b691-4fad-a78e-f049000850eb - - - a82e287f-e142-40d8-ad29-f065ac2e2893 - INFO - - - - - - - Start container: <%= CHEF_SERVER_CONTAINER_NAME %> - Start <%= CHEF_SERVER_CONTAINER_NAME %> - - chef_server-control - - a82e287f-e142-40d8-ad29-f065ac2e2893 - - - e6246fc8-9101-413c-a8e2-c2300b01aca8 - INFO - - - - - - - Shutdown container: <%= CHEF_SERVER_CONTAINER_NAME %> - Stop <%= CHEF_SERVER_CONTAINER_NAME %> - - chef_server-control - - e6246fc8-9101-413c-a8e2-c2300b01aca8 - - diff --git a/install b/install index 1469387..a80b18e 100755 --- a/install +++ b/install @@ -1,4 +1,5 @@ #!/bin/bash -e + echo "Welcome to:" echo "-----------" echo " __ __ __ __ __ ___ __ __" @@ -6,9 +7,6 @@ echo " |\/| | /__\` /__\` | / \\ |\\ | / \` / \\ |\\ | | |__) / \\ |" echo " | | | .__/ .__/ | \\__/ | \\| ___ \\__, \\__/ | \\| | | \\ \\__/ |___" echo -e "\n\nInstallation is progress...\n" sudo apt-get -q update -sudo apt-get -y install build-essential curl uuid-runtime ruby2.3 ruby2.3-dev -echo "Installing: bundler" -sudo gem install bundler --no-ri --no-rdoc -bundle install -ruby=`which ruby` -sudo $ruby scripts/menu_main.rb +sudo apt-get -y install build-essential curl uuid-runtime ruby2.3 ruby2.3-dev libxml2 libxml2-dev libxslt1-dev gcc make zlib1g-dev ruby-dev liblzma-dev +sudo gem install json colorize ffi nokogiri --no-ri --no-rdoc --conservative +sudo ruby scripts/menu_main.rb diff --git a/kvm/chef_generate_scripts.rb b/kvm/chef_generate_scripts.rb index ce6fea1..196603a 100644 --- a/kvm/chef_generate_scripts.rb +++ b/kvm/chef_generate_scripts.rb @@ -11,7 +11,7 @@ def chef_generate_scripts(backend, kvm_folder, floating, bind9) file.puts xml_content end - system("#{dir}/../scripts/create_rd_projects.sh \"kvm-control_with-Chef\" #{kvm_folder}") - system("sudo chown -R rundeck. #{kvm_folder}") + system("#{dir}/../scripts/rd_cmd.sh \"kvm-control_with-Chef\" #{kvm_folder}") + system("chown -R rundeck. #{kvm_folder}") end diff --git a/kvm/generate_scripts-floating.rb b/kvm/generate_scripts-floating.rb index a6c751b..abf217d 100644 --- a/kvm/generate_scripts-floating.rb +++ b/kvm/generate_scripts-floating.rb @@ -4,11 +4,14 @@ def generate_scripts(backend, database_name, db_kvm_table, mysql_password, kvm_folder, start_ip, end_ip, gateway_ip, ssh_keys, floating, rundeck_key, bind9, ip_host) dir=File.expand_path(File.dirname(__FILE__)) - #Generate ENV file - template = ERB.new(File.read("#{dir}/templates/ENV.erb")) - xml_content = template.result(binding) - File.open("#{kvm_folder}/ENV", "w") do |file| - file.puts xml_content + #Generate ENV and rundeck_jobs.xml files + misc_files = ["rundeck_jobs.xml", "ENV"] + misc_files.each do |misc| + template = ERB.new(File.read("#{dir}/templates/#{misc}.erb")) + xml_content = template.result(binding) + File.open("#{kvm_folder}/#{misc}", "w") do |file| + file.puts xml_content + end end #Generate lib files @@ -21,17 +24,7 @@ def generate_scripts(backend, database_name, db_kvm_table, mysql_password, kvm_f end end - #Generate misc files - misc_files = ["rundeck_jobs.xml", "get_images.rb"] - misc_files.each do |misc| - template = ERB.new(File.read("#{dir}/templates/#{misc}.erb")) - xml_content = template.result(binding) - File.open("#{kvm_folder}/#{misc}", "w") do |file| - file.puts xml_content - end - end - - system("#{dir}/../scripts/create_rd_projects.sh \"kvm-control\" #{kvm_folder}") + system("#{dir}/../scripts/rd_cmd.sh \"kvm-control\" #{kvm_folder}") #Generate user-data template files user_data_templates=["TEMPLATE-user-data", "TEMPLATE-user-data-nat"].each do |ud| @@ -44,8 +37,8 @@ def generate_scripts(backend, database_name, db_kvm_table, mysql_password, kvm_f end end - system("sudo cp #{dir}/templates/TEMPLATE.xml.erb #{kvm_folder}/templates/") - system("sudo chown -R rundeck. #{kvm_folder}") + system("cp #{dir}/templates/TEMPLATE.xml.erb #{kvm_folder}/templates/") + system("chown -R rundeck. #{kvm_folder}") puts "\nAll the scripts were generated!\n Mission_Control folder location: #{kvm_folder}\n Backend: #{backend}\n Floating IP Range: #{start_ip} to #{end_ip}" end diff --git a/kvm/generate_scripts.rb b/kvm/generate_scripts.rb index 6d42b6d..306fa3c 100644 --- a/kvm/generate_scripts.rb +++ b/kvm/generate_scripts.rb @@ -4,11 +4,14 @@ def generate_scripts(backend, database_name, db_kvm_table, mysql_password, kvm_folder, ssh_keys, floating, rundeck_key, bind9, ip_host) dir=File.expand_path(File.dirname(__FILE__)) - #Generate ENV file - template = ERB.new(File.read("#{dir}/templates/ENV.erb")) - xml_content = template.result(binding) - File.open("#{kvm_folder}/ENV", "w") do |file| - file.puts xml_content + #Generate ENV and rundeck_jobs.xml files + misc_files = ["rundeck_jobs.xml", "ENV"] + misc_files.each do |misc| + template = ERB.new(File.read("#{dir}/templates/#{misc}.erb")) + xml_content = template.result(binding) + File.open("#{kvm_folder}/#{misc}", "w") do |file| + file.puts xml_content + end end #Generate lib files @@ -21,17 +24,7 @@ def generate_scripts(backend, database_name, db_kvm_table, mysql_password, kvm_f end end - #Generate misc files - misc_files = ["rundeck_jobs.xml", "get_images.rb"] - misc_files.each do |misc| - template = ERB.new(File.read("#{dir}/templates/#{misc}.erb")) - xml_content = template.result(binding) - File.open("#{kvm_folder}/#{misc}", "w") do |file| - file.puts xml_content - end - end - - system("#{dir}/../scripts/create_rd_projects.sh \"kvm-control\" #{kvm_folder}") + system("#{dir}/../scripts/rd_cmd.sh \"kvm-control\" #{kvm_folder}") #Generate user-data template file var = "<%= ip %>" @@ -42,8 +35,8 @@ def generate_scripts(backend, database_name, db_kvm_table, mysql_password, kvm_f file.puts xml_content end - system("sudo cp #{dir}/templates/TEMPLATE.xml.erb #{kvm_folder}/templates/") - system("sudo chown -R rundeck. #{kvm_folder}") + system("cp #{dir}/templates/TEMPLATE.xml.erb #{kvm_folder}/templates/") + system("chown -R rundeck. #{kvm_folder}") puts "\nAll the scripts were generated!\n Mission_Control folder location: #{kvm_folder}\n Backend: #{backend}" end diff --git a/kvm/get_first_cloud_image.rb b/kvm/get_first_cloud_image.rb deleted file mode 100644 index 4994967..0000000 --- a/kvm/get_first_cloud_image.rb +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/ruby - -def get_first_cloud_image(kvm_folder, first_image_source) - filename = first_image_source.split(/\?/).first.split(/\//).last - if File.exist?(kvm_folder+"/sources/cloud_images/"+filename) - puts "#{filename} is already in #{kvm_folder}/sources/cloud_images/ skipping..." - elsif File.exist?(kvm_folder+"/sources/iso/"+filename) - puts "#{filename} is already in #{kvm_folder}/sources/iso/ skipping..." - else - system("sudo ruby #{kvm_folder}/get_images.rb #{first_image_source}") - end -end diff --git a/kvm/setup_db.rb b/kvm/setup_db.rb index 3dfbc1a..14126dd 100644 --- a/kvm/setup_db.rb +++ b/kvm/setup_db.rb @@ -3,7 +3,7 @@ def setup_kvm_db(backend, database_name, db_kvm_table, mysql_password) if backend == "mysql" begin - bundle_install "mysql2" + system("gem install mysql2 --no-ri --no-rdoc --conservative") Gem.clear_paths require 'mysql2' client = Mysql2::Client.new(:host => "localhost", :username => "root", :password => mysql_password) @@ -16,8 +16,9 @@ def setup_kvm_db(backend, database_name, db_kvm_table, mysql_password) puts "\nDatabase \"#{database_name}\" created!" elsif backend == "postgres" begin + system("gem install pg --no-ri --no-rdoc --conservative") + Gem.clear_paths system("createdb -p 5432 -O pguser -U pguser -E UTF8 #{database_name}") - bundle_install "pg" require 'pg' conn = PG::Connection.open(:dbname => "#{database_name}", :user => "pguser") conn.exec_params("CREATE TABLE IF NOT EXISTS #{db_kvm_table} ( @@ -26,5 +27,8 @@ def setup_kvm_db(backend, database_name, db_kvm_table, mysql_password) puts e.error end puts "\nDatabase \"#{database_name}\" created!" + else + puts "BACKEND variable must be: 'mysql' OR 'postgres'! Please update 'vars' file!" + exit 1 end end diff --git a/kvm/templates/chef-rundeck_jobs.xml.erb b/kvm/templates/chef-rundeck_jobs.xml.erb index 5acf328..c8fae99 100644 --- a/kvm/templates/chef-rundeck_jobs.xml.erb +++ b/kvm/templates/chef-rundeck_jobs.xml.erb @@ -1,355 +1,226 @@ - - - 0ecde969-5e0e-4911-a775-30e22b567ea6 + + + + + + Bootstrap a guest to the Docker Chef server. + true + cac7cc96-2721-4d2e-bd1c-7f5655a0dd11 INFO - + 4.Bootstrap guest + true + true + - +puts "\n#{ENV['RD_OPTION_NAME']} is now bootstrapped to the Chef server!".cyan]]> + + + + - Will use the guest's xml and start the vm with VIRSH. - 3.Create VIRSH guest - - kvm-control_with-Chef - - - - 0ecde969-5e0e-4911-a775-30e22b567ea6 + cac7cc96-2721-4d2e-bd1c-7f5655a0dd11 - eb389931-e126-45aa-9709-87e9d7c062fa + Delete both Chef containers. + true + a3a622f8-2e00-4942-bc6d-ce0f8f0b6088 INFO - + Docker: Delete chef-server and chef-rundeck containers + true + true + - - - - - - + + + + + + + + + a3a622f8-2e00-4942-bc6d-ce0f8f0b6088 + + + Restart chef-rundeck container to have the lastest node list. + true + aafaf955-50c1-4db0-a1f0-06126fceb450 + INFO + Docker: Restart chef-rundeck + false + true + + + docker restart chef-rundeck + + + + + + + + aafaf955-50c1-4db0-a1f0-06126fceb450 + + + Start both Chef containers. + true + 1732d47e-23bf-495b-969c-cb8d45b49c10 + INFO + Docker: Start chef-server and chef-rundeck containers + true + true + + + +puts "Done!".bold]]> + + + + + + - This will generate a guest XML. - 2.Create guest XML - - kvm-control_with-Chef - - - <% if floating == "yes" %> - <% elsif floating == "no" %><% end %> - - - - - eb389931-e126-45aa-9709-87e9d7c062fa + 1732d47e-23bf-495b-969c-cb8d45b49c10 - 340bfb41-a016-4664-b29e-1850525476a6 + Stop both Chef containers. + true + 8a7a644c-3415-4db0-96b7-d7f30a395598 INFO - + Docker: Stop chef-server and chef-rundeck containers + true + true + - - - - - - +puts "Done!".bold]]> + - Create a QEMU file for KVM. - 1.Create image disk + 8a7a644c-3415-4db0-96b7-d7f30a395598 + + - kvm-control_with-Chef - - - 340bfb41-a016-4664-b29e-1850525476a6 - - - d178c0da-7b26-46dd-89ee-76f10b4adc09 + Destroy a vm and remove all its files. + true + d19116c4-98a7-4153-8139-52c88a435953 INFO - + KVM: Delete guest + true + true + - - - - Destroy a vm and remove all its files. - Delete guest - - kvm-control_with-Chef - - - - - d178c0da-7b26-46dd-89ee-76f10b4adc09 - - - 89f2efe8-2091-430a-88a6-07a992c77862 - INFO - - - - - - - - - - - - - - - + - - - + - Launch a new instance! - .Launch KVM guest + d19116c4-98a7-4153-8139-52c88a435953 + + - kvm-control_with-Chef - - - 89f2efe8-2091-430a-88a6-07a992c77862 - - - 50fefa5d-7344-40b3-93d2-07e8ec34e56d - INFO - - - - - - - Deleting a source file. Ubuntu Cloud Image or ISO. - Delete source file - - kvm-control_with-Chef - - - 50fefa5d-7344-40b3-93d2-07e8ec34e56d - - - 738919ad-06cb-4cb2-83dd-ec7117f7358e + Launch a new instance! + true + 42d8f84b-ee23-4fac-bab9-2c07b6b422bd INFO + .Launch KVM guest + true + true - - + + + - - Adding a new source file. Ubuntu Cloud Image or ISO. - Add source file - - kvm-control_with-Chef - - - - - 738919ad-06cb-4cb2-83dd-ec7117f7358e - - - daccc0e0-852c-44cb-af11-f1782943b88b - INFO - - - + + + - - Start a vm. - Start guest - - kvm-control_with-Chef - - - - - daccc0e0-852c-44cb-af11-f1782943b88b - - - 5a86aa1c-7ef2-4631-94e5-d5487ccb5414 - INFO - - - + + + - Stop a vm. - Stop guest - - kvm-control_with-Chef - - - - - 5a86aa1c-7ef2-4631-94e5-d5487ccb5414 + 42d8f84b-ee23-4fac-bab9-2c07b6b422bd - ad824dcf-169d-46eb-ba90-2eb39646518d + Destroy all vms and remove all their files. + true + eaa03caf-e741-4233-ab81-59425cb478df INFO + KVM: Delete all guests + true + true - - - - Get a list of all the guests' info. - List ALL guests info - - kvm-control_with-Chef - - ad824dcf-169d-46eb-ba90-2eb39646518d - - - 3cbeda79-5d8f-4658-be67-a63fa62024e4 - INFO - - - - - - - Starting all the guests. - Start ALL non-running guests - - kvm-control_with-Chef - - 3cbeda79-5d8f-4658-be67-a63fa62024e4 - - - 3b2eb65d-00ef-47e6-bb93-64fbc6975768 - INFO - - - - + - - Stopping all the guests. - Stop ALL guests - - kvm-control_with-Chef - - 3b2eb65d-00ef-47e6-bb93-64fbc6975768 - - - eb6f541a-46ee-4a38-91e7-35e67ca8984e - INFO - - - + - Bootstrap a guest to the Docker Chef server. - 4.Bootstrap guest - - kvm-control_with-Chef - - - - - eb6f541a-46ee-4a38-91e7-35e67ca8984e + eaa03caf-e741-4233-ab81-59425cb478df diff --git a/kvm/templates/get_images.rb.erb b/kvm/templates/get_images.rb.erb deleted file mode 100755 index 6872b37..0000000 --- a/kvm/templates/get_images.rb.erb +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/ruby - -guest="" -eval File.read("<%= kvm_folder %>/ENV") -require_relative "#{LIB}/lists.rb" - -if ARGV[0].nil? - puts "This script will download and place any ISO or Cloud Image to the correct location" - puts "For Ubuntu ISO, go to: http://mirror.anl.gov/pub/ubuntu-iso/DVDs/ubuntu/" - puts "For Ubuntu Cloud Image, go to: https://cloud-images.ubuntu.com/" - puts "\nUsage: get_images.rb URL" - exit 1 -end - -url=ARGV[0] -filename = ARGV[0].split(/\?/).first.split(/\//).last - -if url.end_with? "img" - type="cloud_image" - puts "\nDownloading #{filename}...\n" - system("wget #{url} -P #{CLOUD_IMAGES}") or raise "Error while downloading that Cloud Image. Wrong URL maybe?" -elsif url.end_with? "iso" - type="iso" - puts "\nDownloading #{filename}...\n" - system("wget #{url} -P #{ISO}") or raise "Error while downloading that ISO. Wrong URL maybe?" -else - puts "\nDoesn't support this type of source" - puts "Must be ISO or Cloud Image\n" - exit 1 -end - - add_to_list "source", filename, type - system("chown rundeck. <%= kvm_folder %>/lists/source_list.json") - puts "Download completed!".cyan diff --git a/kvm/templates/named.conf.local.erb b/kvm/templates/named.conf.local.erb index 5a8ac4d..576d4b3 100644 --- a/kvm/templates/named.conf.local.erb +++ b/kvm/templates/named.conf.local.erb @@ -9,7 +9,7 @@ zone "122.168.192.in-addr.arpa" { file "/etc/bind/db.1XX"; }; -<% unless floating == "no" %>zone "<%= third_octet %>.168.192.in-addr.arpa" { +<% unless floating == "no" %>zone "<%= third_byte %>.168.192.in-addr.arpa" { type master; notify no; file "/etc/bind/db.1XX"; diff --git a/kvm/templates/rundeck_jobs.xml.erb b/kvm/templates/rundeck_jobs.xml.erb index b15f5c4..b4a5771 100644 --- a/kvm/templates/rundeck_jobs.xml.erb +++ b/kvm/templates/rundeck_jobs.xml.erb @@ -1,80 +1,108 @@ - - - 0ecde969-5e0e-4911-a775-30e22b567ea6 + + + + + + + + Create a QEMU file for KVM. + true + 41c655a6-4c98-4b9e-bdd5-3704ad7cbb92 INFO - + 1.Create image disk + true + true + - + + + + + +puts "\nNew image info:".underline +system("qemu-img info #{KVM_GUEST_IMAGE}/#{guest}.img") +puts ""]]> + - Will use the guest's xml and start the vm with VIRSH. - 3.Create VIRSH guest + 41c655a6-4c98-4b9e-bdd5-3704ad7cbb92 + + - kvm-control - - - 0ecde969-5e0e-4911-a775-30e22b567ea6 - - - eb389931-e126-45aa-9709-87e9d7c062fa + This will generate a guest XML. + true + c36ab893-f554-4d05-991a-b2ffbb3cabde INFO - + 2.Create guest XML + true + true + - + - + - This will generate a guest XML. - 2.Create guest XML + c36ab893-f554-4d05-991a-b2ffbb3cabde + + - kvm-control - - - <% if floating == "yes" %> - <% elsif floating == "no" %><% end %> - - + + - eb389931-e126-45aa-9709-87e9d7c062fa - - - 340bfb41-a016-4664-b29e-1850525476a6 + Will use the guest's xml and start the vm with VIRSH. + true + e5208703-0365-474e-a037-f2633f4c3b5f INFO - + 3.Create VIRSH guest + true + true + - - - - - - +<% if backend == "mysql" %> +require_relative "#{LIB}/mysql_backend.rb"<% elsif backend == "postgres" %> +require_relative "#{LIB}/postgres_backend.rb"<% end %> +ip = guest_ip guest + +puts "Wait while #{guest} comes up".bold +system(" +IP=\"#{ip}\" +CODE=1 +TIMEOUT=200 +TRIES=0 +echo \"Blocking until ${IP} responds...\" +echo \"Number of tries: ${TIMEOUT}\" +echo \"\" +while [ $CODE -ne 0 ]; do + echo \"Try number: $TRIES/$TIMEOUT\" + ping -c 1 $IP >/dev/null + CODE=$? + TRIES=$(( $TRIES + 1 )) + if [ $TRIES -ge $TIMEOUT ]; then + echo \"$IP is not available after $TRIES seconds...stopping the install!\" + exit 1 + fi +done; +echo \"#{guest} is ready, you can now SSH in with: ubuntu@$IP\"") + +with_chef=ENV['RD_OPTION_WITH_CHEF'] +unless with_chef.nil? + if with_chef == "yes" + puts "\nBootstrapping #{guest} with 'chef-server'!\n".bold + system("rd run -p kvm-control -j \"4.Bootstrap guest\" -f -- -name #{guest}") or raise "Couldn't bootstrap #{guest} on chef-server...".red + end +end +]]> + - Create a QEMU file for KVM. - 1.Create image disk + e5208703-0365-474e-a037-f2633f4c3b5f + + - kvm-control - - - 340bfb41-a016-4664-b29e-1850525476a6 - - - d178c0da-7b26-46dd-89ee-76f10b4adc09 + Destroy a vm and remove all its files. + true + d19116c4-98a7-4153-8139-52c88a435953 INFO - + KVM: Delete guest + true + true + - + - Destroy a vm and remove all its files. - Delete guest - - kvm-control - - - - - d178c0da-7b26-46dd-89ee-76f10b4adc09 + d19116c4-98a7-4153-8139-52c88a435953 - 89f2efe8-2091-430a-88a6-07a992c77862 + Get a list of all the guests' info. + true + b164cd29-0676-4901-adf0-920a00162aa1 INFO - - - - - - - - - - - + KVM: List all guests info + true + true + - - - + + - Launch a new instance! - .Launch KVM guest - - kvm-control - - - <% if floating == "yes" %> - <% elsif floating == "no" %><% end %> - - - - - - 89f2efe8-2091-430a-88a6-07a992c77862 + b164cd29-0676-4901-adf0-920a00162aa1 - 50fefa5d-7344-40b3-93d2-07e8ec34e56d + Starting all the guests. + true + 324882e4-242d-4a68-8221-828c1a64fcc9 INFO + KVM: Start all guests + true + true - +sleep 3 +system("virsh list --all")]]> + - Deleting a source file. Ubuntu Cloud Image or ISO. - Delete source file + 324882e4-242d-4a68-8221-828c1a64fcc9 + + - kvm-control - - - 50fefa5d-7344-40b3-93d2-07e8ec34e56d - - - 738919ad-06cb-4cb2-83dd-ec7117f7358e + Start a guest. + true + 03a68476-ee77-491c-bce9-50a46510242a INFO + KVM: Start guest + true + true - +sleep 3 +system("virsh list --all |grep #{guest}")]]> + - Adding a new source file. Ubuntu Cloud Image or ISO. - Add source file - - kvm-control - - - - - 738919ad-06cb-4cb2-83dd-ec7117f7358e + 03a68476-ee77-491c-bce9-50a46510242a - daccc0e0-852c-44cb-af11-f1782943b88b + Stopping all the guests. + true + 395f0f37-90d1-4308-941a-5b937278d6b1 INFO - + KVM: Stop all guests + true + true + - - +system("virsh list --all") +]]> + - Start a vm. - Start guest + 395f0f37-90d1-4308-941a-5b937278d6b1 + + - kvm-control - - - daccc0e0-852c-44cb-af11-f1782943b88b - - - 5a86aa1c-7ef2-4631-94e5-d5487ccb5414 + Stop a guest. + true + 345ce20c-b2a5-4af3-b7e4-21c81315497d INFO + KVM: Stop guest + true + true - - +system("virsh list --all") +]]> + - Stop a vm. - Stop guest + 345ce20c-b2a5-4af3-b7e4-21c81315497d + + - kvm-control - - - 5a86aa1c-7ef2-4631-94e5-d5487ccb5414 + Launch a new instance! + true + 42d8f84b-ee23-4fac-bab9-2c07b6b422bd + INFO + .Launch KVM guest + true + true + + + + + + + + + + + + + + + + + + 42d8f84b-ee23-4fac-bab9-2c07b6b422bd - ad824dcf-169d-46eb-ba90-2eb39646518d + + + + + + Adding a new source file. Ubuntu Cloud Image or ISO. + true + 99e0fc01-29c6-4e3a-9e50-bed6841c0f58 INFO + Source: Add Cloud Image or ISO + true + true - +url=ENV['RD_OPTION_URL'] +action=ENV['RD_OPTION_ACTION'] +filename = url.split("/")[-1] + +if url.end_with? "img" + type="cloud_image" + if File.exist?("<%= kvm_folder %>/sources/cloud_images/"+filename) + puts "#{filename} is already in <%= kvm_folder %>/sources/cloud_images/ skipping..." + else + puts "\nDownloading #{filename}...\n" + system("wget #{url} -P #{CLOUD_IMAGES}") or raise "Error while downloading that Cloud Image. Wrong URL maybe?" + add_to_list "source", filename, type + puts "Download completed!".cyan + end +elsif url.end_with? "iso" + type="iso" + if File.exist?("<%= kvm_folder %>/sources/iso/"+filename) + puts "#{filename} is already in <%= kvm_folder %>/sources/iso/ skipping..." + else + puts "\nDownloading #{filename}...\n" + system("wget #{url} -P #{ISO}") or raise "Error while downloading that ISO. Wrong URL maybe?" + add_to_list "source", filename, type + puts "Download completed!".cyan + end +else + puts "\nDoesn't support this type of source" + puts "Must be ISO or Cloud Image\n" + exit 1 +end]]> + - Get a list of all the guests' info. - List ALL guests info - - kvm-control - - ad824dcf-169d-46eb-ba90-2eb39646518d + 99e0fc01-29c6-4e3a-9e50-bed6841c0f58 - 3cbeda79-5d8f-4658-be67-a63fa62024e4 + + + + + + Deleting a source file. Ubuntu Cloud Image or ISO. + true + 4cc7575e-585e-4511-8dbf-43b13ed59cce INFO + Source: Delete Cloud Image or ISO + true + true - + delete_from_list "source", file, type + puts "Source: #{file} deleted!".cyan]]> + - Starting all the guests. - Start ALL non-running guests - - kvm-control - - 3cbeda79-5d8f-4658-be67-a63fa62024e4 + 4cc7575e-585e-4511-8dbf-43b13ed59cce - 3b2eb65d-00ef-47e6-bb93-64fbc6975768 + Destroy all vms and remove all their files. + true + eaa03caf-e741-4233-ab81-59425cb478df INFO - + KVM: Delete all guests + true + true + - + - Stopping all the guests. - Stop ALL guests - - kvm-control - - 3b2eb65d-00ef-47e6-bb93-64fbc6975768 + eaa03caf-e741-4233-ab81-59425cb478df diff --git a/scripts/check_url.sh b/scripts/check_url.sh index 4670df6..c2b2019 100755 --- a/scripts/check_url.sh +++ b/scripts/check_url.sh @@ -26,7 +26,7 @@ if [ "$OPTION" == "url" ]; then echo -n "." if [ "$SECONDS" -ge "$TIMEOUT" ]; then - echo "$txtred$URL is not available after $SECONDS seconds...stopping the install!" + echo "$txtred $URL is not available after $SECONDS seconds...stopping the install!" exit 1 fi done; @@ -37,21 +37,21 @@ elif [ "$OPTION" == "file" ]; then SIZE=0 echo -e "Blocking until $URL is accessible...\nTimeout: $TIMEOUT seconds." - while [ $SIZE -lt $TARGET_SIZE ]; do + while [ "$SIZE" -lt "$TARGET_SIZE" ]; do SIZE=$(curl -Isk $URL | grep Content-Length | awk '{print $2}' | tr -d '\r\n') sleep 2 echo -n "." if [ "$SECONDS" -ge "$TIMEOUT" ]; then - echo "$txtred$URL is not available after $SECONDS seconds...stopping the install!" + echo "$txtred $URL is not available after $SECONDS seconds...stopping the install!" exit 1 fi done; else - echo "$txtred$OPTION is not a valid choice. Please use 'url' or 'file'!" + echo "$txtred $OPTION is not a valid choice. Please use 'url' or 'file'!" exit 1 fi -echo -e "\n$txtbold$URL$txtreset is accessible!" \ No newline at end of file +echo -e "\n$txtbold $URL $txtreset is accessible!" diff --git a/scripts/create_rd_projects.sh b/scripts/create_rd_projects.sh deleted file mode 100755 index 34526e6..0000000 --- a/scripts/create_rd_projects.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -txtbold=$(tput bold) - -case "$1" in - "kvm-control" ) - project=$(sudo su - rundeck -c "rd projects list |grep $1") - if [[ -z "$project" ]]; then - echo -e "$txtboldCreating $1 project and jobs!\n" - sudo su rundeck -c "rd projects create -p kvm-control" - sudo su rundeck -c "rd jobs load -r -f $2/rundeck_jobs.xml -p kvm-control" - else - echo -e "$1 project and jobs already created!\n" - fi - ;; - "kvm-control_with-Chef" ) - project=$(sudo su - rundeck -c "rd projects list |grep $1") - if [[ -z "$project" ]]; then - echo -e "$txtboldCreating $1 project and jobs!\n" - sudo su rundeck -c "rd projects create -p kvm-control_with-Chef -- --resources.source.2.config.url=http://localhost:9980 --resources.source.2.type=url --resources.source.2.config.timeout=60 --resources.source.2.config.cache=false" - sudo su rundeck -c "rd jobs load -r -f $2/chef-rundeck_jobs.xml -p kvm-control_with-Chef" - else - echo -e "$1 project and jobs already created!\n" - fi - ;; - "docker-control" ) - project=$(sudo su - rundeck -c "rd projects list |grep $1") - if [[ -z "$project" ]]; then - echo -e "$txtboldCreating $1 project and jobs!\n" - sudo su rundeck -c "rd projects create -p docker-control" - sudo su rundeck -c "rd jobs load -r -f $2/rundeck_jobs.xml -p docker-control" - else - echo -e "$1 project and jobs already created!\n" - fi - ;; - "chef_server-control" ) - project=$(sudo su - rundeck -c "rd projects list |grep $1") - if [[ -z "$project" ]]; then - echo -e "$txtboldCreating $1 project and jobs!\n" - sudo su rundeck -c "rd projects create -p chef_server-control" - sudo su rundeck -c "rd jobs load -r -f $2/rundeck_jobs-chef.xml -p chef_server-control" - else - echo -e "$1 project and jobs already created!\n" - fi - ;; -esac diff --git a/scripts/fetch_chef_keys.sh b/scripts/fetch_chef_keys.sh new file mode 100755 index 0000000..0b3ae4d --- /dev/null +++ b/scripts/fetch_chef_keys.sh @@ -0,0 +1,31 @@ +#!/bin/bash +txtbold=$(tput bold) +echo -e "$txtbold Fetching Knife keys\n" +# Check if the archive containg the knife key is accessible and then download it +scripts/check_url.sh file https://"$1":"$2"/knife_admin_key.tar.gz 2500 900 +curl -o "$3"/"$1"/knife_admin_key.tar.gz -Ok https://"$1":"$2"/knife_admin_key.tar.gz +# Create two .chef folders, one for the current user and one for the rundeck user +knife_keys=( /var/lib/rundeck ~ ) +for i in "${knife_keys[@]}" + do + mkdir -p "$i"/.chef + cat > "$i"/.chef/config.rb << EOL +log_level :info +log_location STDOUT +cache_type 'BasicFile' +node_name 'admin' +client_key '$i/.chef/admin.pem' +chef_server_url 'https://$1:$2/organizations/my_org' +EOL + # Extract Knife keys into .chef folders + tar -zxf "$3"/"$1"/knife_admin_key.tar.gz -C "$i"/.chef/ +done +chown -R rundeck. /var/lib/rundeck/.chef/ +# Get SSL certs +knife ssl fetch +knife user list +su - rundeck -c "knife ssl fetch && knife user list" +chown rundeck. -R "$3"/"$1" +echo -e "\nCreating knife keys for rundeck and $SUDO_USER users!\n" +chown rundeck. -R /var/lib/rundeck/.chef/ +chown "$SUDO_USER". -R ~/.chef/ diff --git a/scripts/get_and_install.sh b/scripts/get_and_install.sh index 5fdef60..52938a0 100755 --- a/scripts/get_and_install.sh +++ b/scripts/get_and_install.sh @@ -6,8 +6,8 @@ case "$1" in "rundeck-cli" ) file=$(for i in /etc/apt/sources.list.d/*; do echo "$i" |grep rundeck-cli.list; done) if [[ -z "$file" ]]; then - echo -e "$txtboldDownloading $1!\n" - echo "deb https://dl.bintray.com/rundeck/rundeck-deb /" | sudo tee -a /etc/apt/sources.list.d/rundeck-cli.list + echo -e "$txtbold Downloading $1!\n" + echo "deb https://dl.bintray.com/rundeck/rundeck-deb /" | tee -a /etc/apt/sources.list.d/rundeck-cli.list curl "https://bintray.com/user/downloadSubjectPublicKey?username=bintray" > /tmp/bintray.gpg.key apt-key add - < /tmp/bintray.gpg.key apt-get -y install apt-transport-https @@ -19,7 +19,7 @@ case "$1" in "rundeck" ) file=$(for i in *; do echo "$i" |grep rundeck-"$2"-GA.deb; done) if [[ -z "$file" ]]; then - echo -e "$txtboldDownloading $1!\n" + echo -e "$txtbold Downloading $1!\n" wget http://download.rundeck.org/deb/rundeck-"$2"-GA.deb dpkg -i rundeck-"$2"-GA.deb rm -rf /tmp/rundeck/ @@ -29,15 +29,4 @@ case "$1" in echo -e "$1 is already on this server!\n" fi ;; - "mysql-connector" ) - file=$(for i in *; do echo "$i" |grep mysql-connector-java-5.1.40.tar.gz; done) - if [[ -z "$file" ]]; then - echo -e "$txtboldDownloading $1!\n" - wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz - tar -zxf mysql-connector-java-5.1.40.tar.gz -C /tmp/ - cp /tmp/mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar /var/lib/rundeck/libext/ - else - echo -e "$1 is already on this server!\n" - fi - ;; esac diff --git a/scripts/get_interface_ip.rb b/scripts/get_interface_ip.rb deleted file mode 100755 index 10eb028..0000000 --- a/scripts/get_interface_ip.rb +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/ruby - -if ARGV[0] == "yes" - ip=`curl http://icanhazip.com` -else - ip=`ifconfig #{ARGV[1]} |grep "inet addr" |awk '{print $2}' |cut -d ':' -f 2` -end - -puts ip diff --git a/scripts/install_docker.sh b/scripts/install_docker.sh index de6a5dd..88f87ce 100755 --- a/scripts/install_docker.sh +++ b/scripts/install_docker.sh @@ -2,10 +2,17 @@ txtbold=$(tput bold) -echo -e "$txtboldInstalling Docker...\n" -sudo apt-get -y install docker.io -sudo adduser rundeck docker -sudo mkdir -p "$1" +echo -e "$txtbold Installing Docker...\n" +apt-get -y install docker.io +adduser rundeck docker +mkdir -p "$1" cp docker/rundeck_jobs.xml "$1" -sudo chown rundeck. -R "$1" -sudo docker network create --subnet=172.18.0.0/16 mc_net +chown rundeck. -R "$1" +docker network create --subnet=172.18.0.0/16 mc_net + +# Restart Rundeck only once to apply new permissions (added rundeck to docker group) +if [ ! -f rundeck_restarted_docker ]; then + systemctl restart rundeckd + scripts/check_url.sh url http://"$2":4440 60 + touch rundeck_restarted_docker +fi diff --git a/scripts/install_docker_chef-rundeck.sh b/scripts/install_docker_chef-rundeck.sh index 7fc0bbf..558b800 100755 --- a/scripts/install_docker_chef-rundeck.sh +++ b/scripts/install_docker_chef-rundeck.sh @@ -1,24 +1,25 @@ #!/bin/bash + txtbold=$(tput bold) -chef_rundeck_present=$(sudo docker ps -a |grep "$1") -chef_rundeck_up=$(sudo docker ps |grep "$1") +chef_rundeck_present=$(docker ps -a |grep "$1") +chef_rundeck_up=$(docker ps |grep "$1") chef_rundeck_docker_ip=$2 chef_server_docker_ip=$3 set -e if [[ -z "$chef_rundeck_present" ]]; then - echo -e "$txtboldCreating image, launching container and start $1\n" + echo -e "$txtbold Creating image, launching container and start $1\n" # Create the chef-rundeck Docker image and run it tar -zxf docker/docker_chef_rundeck.tar.gz sed -i "s,CHEF_SERVER_CONTAINER_IP,$3,g" chef-rundeck/Dockerfile sed -i "s,CHEF_SERVER_CONTAINER_IP,$3,g" chef-rundeck/config.rb cp ~/.chef/admin.pem chef-rundeck/ - sudo docker build -t c_rundeck_image chef-rundeck/ - sudo docker run --net mc_net --ip $chef_rundeck_docker_ip -d --name $1 -e 'USER=ubuntu' -p 9980:9980 c_rundeck_image + docker build -t c_rundeck_image chef-rundeck/ + docker run --net mc_net --ip $chef_rundeck_docker_ip -d --name $1 -e 'USER=ubuntu' -p 9980:9980 c_rundeck_image # Get the container's IP and add it to /etc/hosts - grep -q "$chef_rundeck_docker_ip $1" /etc/hosts || echo "$chef_rundeck_docker_ip $1" | sudo tee -a /etc/hosts + grep -q "$chef_rundeck_docker_ip $1" /etc/hosts || echo "$chef_rundeck_docker_ip $1" | tee -a /etc/hosts elif [[ -z "$chef_rundeck_up" ]]; then echo -e "Starting $1 container\n" - sudo docker start "$1" + docker start "$1" else echo -e "\nThere is already a Docker container named: $1\nRemove it first and re-run that script if you want a new container!\n" fi diff --git a/scripts/install_docker_chef-server.sh b/scripts/install_docker_chef-server.sh index 31e2821..1960163 100755 --- a/scripts/install_docker_chef-server.sh +++ b/scripts/install_docker_chef-server.sh @@ -1,49 +1,24 @@ #!/bin/bash txtbold=$(tput bold) -chef_present=$(sudo docker ps -a |grep "$1") -chef_up=$(sudo docker ps |grep "$1") +chef_present=$(docker ps -a |grep "$1") +chef_up=$(docker ps |grep "$1") chef_docker_ip=$4 set -e if [[ -z "$chef_present" ]]; then - echo -e "$txtboldDownloading container and start $1\n" - sudo mkdir -p "$3"/"$1"/logs + DEBIAN_FRONTEND=noninteractive apt-get install -q -y chef + echo -e "$txtbold Downloading container and start $1\n" + mkdir -p "$3"/"$1"/logs # Get the chef-server Docker image and run it docker pull cbuisson/chef-server:v2.3 - sudo docker run --net mc_net --ip $chef_docker_ip --privileged -e CONTAINER_NAME="$1" -e SSL_PORT="$2" --name "$1" -d -v "$3"/"$1"/logs/chef-logs:/var/log -v "$3"/"$1"/logs/install-chef-out:/root -p "$2":"$2" cbuisson/chef-server:v2.3 - # Get the container's IP and add it to /etc/hosts - grep -q "$chef_docker_ip $1" /etc/hosts || echo "$chef_docker_ip $1" | sudo tee -a /etc/hosts + docker run --net mc_net --ip $chef_docker_ip --privileged -e CONTAINER_NAME="$1" -e SSL_PORT="$2" --name "$1" -d -v "$3"/"$1"/logs/chef-logs:/var/log -v "$3"/"$1"/logs/install-chef-out:/root -p "$2":"$2" cbuisson/chef-server:v2.3 + # Add the container's IP to /etc/hosts + grep -q "$chef_docker_ip $1" /etc/hosts || echo "$chef_docker_ip $1" | tee -a /etc/hosts # Check the Chef is running - sudo scripts/check_url.sh url https://"$1":"$2" 900 - # Check if the archive containg the knife key is accessible and then download it - sudo scripts/check_url.sh file https://"$1":"$2"/knife_admin_key.tar.gz 2500 900 - sudo curl -o "$3"/"$1"/knife_admin_key.tar.gz -Ok https://"$1":"$2"/knife_admin_key.tar.gz - sudo DEBIAN_FRONTEND=noninteractive apt-get install -q -y chef - # Create two .chef folders, one for the current user and one for the rundeck user - knife_keys=( /var/lib/rundeck ~ ) - for i in "${knife_keys[@]}" - do - mkdir -p "$i"/.chef - cat > "$i"/.chef/config.rb << EOL -log_level :info -log_location STDOUT -cache_type 'BasicFile' -node_name 'admin' -client_key '$i/.chef/admin.pem' -chef_server_url 'https://$1:$2/organizations/my_org' -EOL - sudo tar -zxf "$3"/"$1"/knife_admin_key.tar.gz -C "$i"/.chef/ - done - sudo chown -R rundeck. /var/lib/rundeck/.chef/ - knife ssl fetch - knife user list - sudo su - rundeck -c "knife ssl fetch && knife user list" - sudo chown rundeck. -R "$3"/"$1" - echo -e "\n\eCreating knife keys for rundeck and $SUDO_USER users!\e" - sudo chown rundeck. -R /var/lib/rundeck/.chef/ - sudo chown "$SUDO_USER". -R ~/.chef/ + scripts/check_url.sh url https://"$1":"$2" 900 + scripts/fetch_chef_keys.sh $1 $2 $3 elif [[ -z "$chef_up" ]]; then echo -e "Starting $1 container\n" - sudo docker start "$1" + docker start "$1" else echo -e "\nThere is already a Docker container named: $1\nRemove it first and re-run that script if you want a new container!\n" fi diff --git a/scripts/install_kvm.sh b/scripts/install_kvm.sh index 786ae3a..97331ed 100755 --- a/scripts/install_kvm.sh +++ b/scripts/install_kvm.sh @@ -1,13 +1,14 @@ #!/bin/bash -sudo apt-get -y install qemu-utils cloud-utils kvm libvirt-bin -sudo mkdir -p "$1"/{kvm_guests,lib,templates,lists,sources/{iso,cloud_images}} +apt-get -y install qemu-utils cloud-utils kvm libvirt-bin libvirt-dev +gem install ruby-libvirt --no-ri --no-rdoc --conservative +mkdir -p "$1"/{kvm_guests,lib,templates,lists,sources/{iso,cloud_images}} echo "Add rundeck user to libvirtd and kvm groups" -sudo adduser rundeck libvirtd && sudo adduser rundeck kvm -kvm_guests=$(sudo virsh list) +adduser rundeck libvirtd && adduser rundeck kvm +kvm_guests=$(virsh list) if [[ -z "$kvm_guests" ]]; then echo "Restart libvirtd..." - sudo systemctl restart libvirt-bin + systemctl restart libvirt-bin fi if [[ $2 == "yes" ]];then @@ -15,16 +16,19 @@ if [[ $2 == "yes" ]];then localhost=$(cat /etc/resolvconf/resolv.conf.d/{head,base} |grep -w "nameserver 127.0.0.1") if [[ -z "$domain" ]];then base=$(cat /etc/resolvconf/resolv.conf.d/base) - sudo echo -e "search local\ndomain local\n$base" |sudo tee /etc/resolvconf/resolv.conf.d/base + echo -e "search local\ndomain local\n$base" |tee /etc/resolvconf/resolv.conf.d/base fi if [[ -z "$localhost" ]];then head=$(cat /etc/resolvconf/resolv.conf.d/head) - sudo echo -e "nameserver 127.0.0.1\n$head" |sudo tee /etc/resolvconf/resolv.conf.d/head + echo -e "nameserver 127.0.0.1\n$head" |tee /etc/resolvconf/resolv.conf.d/head fi - sudo resolvconf -u + resolvconf -u fi -# Restart Rundeck -systemctl restart rundeckd -scripts/check_url.sh url http://"$3":4440 60 -grep -q "export LIBVIRT_DEFAULT_URI=qemu:///system" /etc/environment || echo "export LIBVIRT_DEFAULT_URI=qemu:///system" | sudo tee -a /etc/environment +# Restart Rundeck only once to apply new permissions (added rundeck to libvirtd and kvm groups) +if [ ! -f rundeck_restarted_kvm ]; then + systemctl restart rundeckd + scripts/check_url.sh url http://"$3":4440 60 + grep -q "export LIBVIRT_DEFAULT_URI=qemu:///system" /etc/environment || echo "export LIBVIRT_DEFAULT_URI=qemu:///system" | tee -a /etc/environment + touch rundeck_restarted_kvm +fi diff --git a/scripts/install_rundeck.sh b/scripts/install_rundeck.sh index c203e5d..624050d 100755 --- a/scripts/install_rundeck.sh +++ b/scripts/install_rundeck.sh @@ -15,11 +15,10 @@ if [[ $3 == "mysql" ]]; then mysql-server-5.7 mysql-server/root_password seen true mysql-server-5.7 mysql-server/root_password_again password $4 mysql-server-5.7 mysql-server/root_password_again seen true - " | sudo debconf-set-selections + " | debconf-set-selections export DEBIAN_FRONTEND=noninteractive apt-get install -q -y mysql-server mysql-client libmysqlclient-dev # Setup rundeckdb - scripts/get_and_install.sh "mysql-connector" mysql -u root -p"$4" -e "create database rundeckdb" mysql -u root -p"$4" -e "grant ALL on rundeckdb.* to 'rduser'@'localhost' identified by 'rdpasswd';" sed -i "s,jdbc:h2:file:/var/lib/rundeck/data/rundeckdb;MVCC=true,jdbc:mysql://localhost/rundeckdb?autoReconnect=true,g" /etc/rundeck/rundeck-config.properties @@ -27,7 +26,7 @@ if [[ $3 == "mysql" ]]; then elif [[ "$3" == "postgres" ]]; then apt-get -y install postgresql libpq-dev su - postgres -c "createuser pguser -s" - echo -e "local all postgres peer\nlocal all pguser trust\nlocal all all peer\nhost all all 127.0.0.1/32 md5" | sudo tee /etc/postgresql/9.5/main/pg_hba.conf + echo -e "local all postgres peer\nlocal all pguser trust\nlocal all all peer\nhost all all 127.0.0.1/32 md5" | tee /etc/postgresql/9.5/main/pg_hba.conf systemctl restart postgresql else echo "Backend: $3 not supported!" @@ -38,15 +37,22 @@ fi sed -i s,localhost,"$1",g /etc/rundeck/framework.properties sed -i "s,grails.serverURL=http://localhost:4440,grails.serverURL=http://$1:4440,g" /etc/rundeck/rundeck-config.properties hostname=$(hostname) -grep -q "$1 $hostname" /etc/hosts || echo "$1 $hostname" | sudo tee -a /etc/hosts +grep -q "$1 $hostname" /etc/hosts || echo "$1 $hostname" | tee -a /etc/hosts sed -i "s,/var/lib/rundeck:/bin/false,/var/lib/rundeck:/bin/bash,g" /etc/passwd +# Create rundeck user SSH keys chown rundeck. /var/lib/rundeck -ls /var/lib/rundeck/.ssh || sudo su rundeck -c "echo -e \"\n\" | ssh-keygen -t rsa -N \"\"" -mkdir /var/lib/rundeck/.rd +ls /var/lib/rundeck/.ssh || su rundeck -c "echo -e \"\n\" | ssh-keygen -t rsa -N \"\"" +# Configure rundeck-cli for current and rundeck users +mkdir -p /var/lib/rundeck/.rd +mkdir -p ~/.rd echo -e "export RD_URL=http://$1:4440\nexport RD_USER=admin\nexport RD_PASSWORD=admin" > /var/lib/rundeck/.rd/rd.conf +echo -e "export RD_URL=http://$1:4440\nexport RD_USER=admin\nexport RD_PASSWORD=admin" > ~/.rd/rd.conf chown -R rundeck. /var/lib/rundeck/.rd +chown -R "$SUDO_USER". ~/.rd +# Grant Bind9 access to rundeck user echo "rundeck ALL=NOPASSWD: /bin/systemctl reload bind9" > /etc/sudoers.d/rundeck chmod 440 /etc/sudoers.d/rundeck +# Start Rundeck! systemctl enable rundeckd systemctl restart rundeckd scripts/check_url.sh url http://"$1":4440 60 diff --git a/scripts/menu_chef.rb b/scripts/menu_chef.rb index 5ba374e..2ed0dea 100644 --- a/scripts/menu_chef.rb +++ b/scripts/menu_chef.rb @@ -1,49 +1,37 @@ #!/usr/bin/ruby require 'erb' -def chef_menu +def chef_menu (ip_host) puts "\nDo you want to setup a Docker container with Chef server?".bold puts " 1. Yes".green + " - chef-server-control".bold puts " 2. No".green + puts " 3. Get keys".green + " (chef-server already installed. Re-fetching the admin keys)".bold case gets.strip when "1", "y" - vars= {"chef_server_container_name" => CHEF_SERVER_CONTAINER_NAME, - "chef_server_container_ip" => CHEF_SERVER_CONTAINER_IP, - "chef_rundeck_container_name" => CHEF_RUNDECK_CONTAINER_NAME, - "chef_rundeck_container_ip" => CHEF_RUNDECK_CONTAINER_IP, - "docker_folder" => DOCKER_FOLDER - } - vars=check_vars(vars) - system("sudo scripts/install_docker.sh #{DOCKER_FOLDER}") - get_ip_host + system("scripts/install_docker.sh #{DOCKER_FOLDER} #{ip_host}") system("scripts/install_docker_chef-server.sh #{CHEF_SERVER_CONTAINER_NAME} #{CHEF_PORT} #{DOCKER_FOLDER} #{CHEF_SERVER_CONTAINER_IP}") - generate_rundeck_job chef_rundeck self.class.const_set(:INSTALL_CHEF, "yes") when "2", "n" self.class.const_set(:INSTALL_CHEF, "no") puts "Ok, moving on..." + when "3" + fetch_chef_keys + self.class.const_set(:INSTALL_CHEF, "yes") else chef_menu end end -def generate_rundeck_job - template = ERB.new(File.read("docker/template/rundeck_jobs-chef.xml.erb")) - xml_content = template.result(binding) - File.open("#{DOCKER_FOLDER}/rundeck_jobs-chef.xml", "w") do |file| - file.puts xml_content - end - dir=File.expand_path(File.dirname(__FILE__)) - system("#{dir}/../scripts/create_rd_projects.sh \"chef_server-control\" #{DOCKER_FOLDER}") -end - def chef_rundeck - unless `sudo docker ps |grep chef-rundeck` != "" + unless `docker ps |grep chef-rundeck` != "" puts "Setting up chef-rundeck container".bold - dir=File.expand_path(File.dirname(__FILE__)) system("scripts/install_docker_chef-rundeck.sh #{CHEF_RUNDECK_CONTAINER_NAME} #{CHEF_RUNDECK_CONTAINER_IP} #{CHEF_SERVER_CONTAINER_IP}") else puts "Chef-Rundeck already installed/configured and running. Skipping...".bold end end + +def fetch_chef_keys + system("scripts/fetch_chef_keys.sh #{CHEF_SERVER_CONTAINER_NAME} #{CHEF_PORT} #{DOCKER_FOLDER}") +end diff --git a/scripts/menu_main.rb b/scripts/menu_main.rb index b634b98..d19959c 100644 --- a/scripts/menu_main.rb +++ b/scripts/menu_main.rb @@ -9,6 +9,7 @@ class Installer def initialize + get_ip_host rundeck_menu main_menu end @@ -20,13 +21,7 @@ def rundeck_menu case gets.strip when "1", "y" puts "Installing Rundeck...".bold - vars= {"rundeck_version" => RUNDECK_VERSION, - "backend" => BACKEND, - "mysql_password" => MYSQL_PASSWORD - } - vars=check_vars(vars) - get_ip_host - system("sudo scripts/install_rundeck.sh #{IP_HOST} #{RUNDECK_VERSION} #{BACKEND} #{MYSQL_PASSWORD}") + system("scripts/install_rundeck.sh #{IP_HOST} #{RUNDECK_VERSION} #{BACKEND} #{MYSQL_PASSWORD}") when "2", "n" puts "Moving on..." when "3" @@ -44,91 +39,59 @@ def main_menu puts " 4: Exit..." case gets.strip when "1" - files=["generate_scripts.rb", "chef_generate_scripts.rb", "setup_db.rb", "get_first_cloud_image.rb"] + files=["generate_scripts.rb", "chef_generate_scripts.rb", "setup_db.rb"] files.each do |file| require_relative "../kvm/#{file}" end puts "Installing KVM (NAT only) and generating Rundeck jobs...".bold - vars= {"kvm_folder" => KVM_FOLDER, - "backend" => BACKEND, - "mysql_password" => MYSQL_PASSWORD, - "database_name" => DATABASE_NAME, - "db_kvm_table" => DB_KVM_TABLE, - "ssh_keys" => SSH_KEYS, - "bind9" => BIND9} - vars=check_vars(vars) self.class.const_set(:FLOATING, "no") - get_ip_host - system("sudo scripts/install_kvm.sh #{KVM_FOLDER} #{BIND9} #{IP_HOST}") + system("scripts/install_kvm.sh #{KVM_FOLDER} #{BIND9} #{IP_HOST}") get_rundeck_key generate_scripts BACKEND, DATABASE_NAME, DB_KVM_TABLE, MYSQL_PASSWORD, KVM_FOLDER, SSH_KEYS, FLOATING, RUNDECK_KEY, BIND9, IP_HOST setup_kvm_db BACKEND, DATABASE_NAME, DB_KVM_TABLE, MYSQL_PASSWORD - get_first_cloud_image KVM_FOLDER, FIRST_IMAGE_SOURCE install_bind9 BIND9, FLOATING - chef_menu + chef_menu IP_HOST if INSTALL_CHEF == "yes" chef_generate_scripts BACKEND, KVM_FOLDER, FLOATING, BIND9 + else + system("scripts/rd_cmd.sh \"remove_chef_jobs\" #{KVM_FOLDER}") end - system("sudo chown -R rundeck. #{KVM_FOLDER}") + system("scripts/rd_cmd.sh \"get_first_source\" #{FIRST_IMAGE_SOURCE}") + system("chown -R rundeck. #{KVM_FOLDER}") when "2" - # Check if there is a bridge inteface br0 - br = `ifconfig |grep -w br0` - if br.empty? - puts "Please create a bridge interface in order to use floating IPs!".red - exit 1 - end - files=["generate_scripts-floating.rb", "chef_generate_scripts.rb", "setup_db.rb", "get_first_cloud_image.rb"] + # Check if there is a bridge inteface named 'br0' + if BR0_PRESENT == false + puts "Please create a bridge interface named 'br0' in order to use floating IPs!".red + exit 1 + end + files=["generate_scripts-floating.rb", "chef_generate_scripts.rb", "setup_db.rb"] files.each do |file| require_relative "../kvm/#{file}" end puts "Installing KVM (NAT + Floating IP) and generating Rundeck jobs...".bold - vars= {"kvm_folder" => KVM_FOLDER, - "backend" => BACKEND, - "mysql_password" => MYSQL_PASSWORD, - "database_name" => DATABASE_NAME, - "db_kvm_table" => DB_KVM_TABLE, - "start_ip" => START_IP, + vars={"start_ip" => START_IP, "end_ip" => END_IP, - "gateway_ip" => GATEWAY_IP, - "ssh_keys" => SSH_KEYS, - "bind9" => BIND9} + "gateway_ip" => GATEWAY_IP} vars=check_vars(vars) - # Check if the START_IP, END_IP, GATEWAY_IP variables are loaded - ips = [START_IP, END_IP, GATEWAY_IP] - ips.each do |ip| - begin - IPAddr.new(ip) - rescue - puts "IP (#{ip}) is not valid or nil!\nStopping now...".red - exit 1 - end - end - ip_start = IPAddr.new START_IP - ip_end = IPAddr.new END_IP - if ip_start >= ip_end - puts "START_IP (#{ip_start}) should start before END_IP (#{ip_end})! Please fix!" - exit 1 - end + check_vars_ips_for_floating self.class.const_set(:FLOATING, "yes") - get_ip_host - system("sudo scripts/install_kvm.sh #{KVM_FOLDER} #{BIND9} #{IP_HOST}") + system("scripts/install_kvm.sh #{KVM_FOLDER} #{BIND9} #{IP_HOST}") get_rundeck_key generate_scripts BACKEND, DATABASE_NAME, DB_KVM_TABLE, MYSQL_PASSWORD, KVM_FOLDER, START_IP, END_IP, GATEWAY_IP, SSH_KEYS, FLOATING, RUNDECK_KEY, BIND9, IP_HOST setup_kvm_db BACKEND, DATABASE_NAME, DB_KVM_TABLE, MYSQL_PASSWORD - get_first_cloud_image KVM_FOLDER, FIRST_IMAGE_SOURCE install_bind9 BIND9, FLOATING - chef_menu + chef_menu IP_HOST if INSTALL_CHEF == "yes" chef_generate_scripts BACKEND, KVM_FOLDER, FLOATING, BIND9 + else + system("scripts/rd_cmd.sh \"remove_chef_jobs\" #{KVM_FOLDER}") end - system("sudo chown -R rundeck. #{KVM_FOLDER}") + system("scripts/rd_cmd.sh \"get_first_source\" #{FIRST_IMAGE_SOURCE}") + system("chown -R rundeck. #{KVM_FOLDER}") when "3" puts "Installing Docker and generating Rundeck jobs...".bold - vars= {"docker_folder" => DOCKER_FOLDER} - vars=check_vars(vars) - system("sudo scripts/install_docker.sh #{DOCKER_FOLDER}") - dir=File.expand_path(File.dirname(__FILE__)) - system("#{dir}/../scripts/create_rd_projects.sh \"docker-control\" #{DOCKER_FOLDER}") + system("scripts/install_docker.sh #{DOCKER_FOLDER}") + system("scripts/rd_cmd.sh \"docker-control\" #{DOCKER_FOLDER}") when "4" bye exit 0 @@ -139,27 +102,53 @@ def main_menu end def get_ip_host - ip_host=`sudo scripts/get_interface_ip.rb #{CLOUD_SERVER} #{INTERFACE_OUT}`.chomp - begin - IPAddr.new(ip_host) - self.class.const_set(:IP_HOST, ip_host) - rescue - puts "Host IP (#{ip_host}) is not valid or nil!\nStopping now...".red + # Get host IP + if CLOUD_SERVER == "yes" + ip_host=`curl http://icanhazip.com`.chomp + end + require 'socket' + interfaces={} + addr_infos = Socket.getifaddrs + addr_infos.each do |addr_info| + if addr_info.addr + interfaces[addr_info.name]=addr_info.addr.ip_address if addr_info.addr.ipv4? + end + end + # Check if the interface has an IP + interface_present=interfaces.key?(INTERFACE_OUT) + if interface_present == false + puts "The INTERFACE_OUT (#{INTERFACE_OUT}) does not have any IP assigned to it!".red + puts "Check 'ifconfig' and update 'vars' file accordingly." exit 1 + else + self.class.const_set(:IP_HOST, interfaces[INTERFACE_OUT]) + # Check if there is a bridge inteface named 'br0' + self.class.const_set(:BR0_PRESENT, interfaces.key?('br0')) end end - def bundle_install(gem) - require 'erb' - template = ERB.new(File.read("scripts/templates/Gemfile.erb")) - xml_content = template.result(binding) - File.open("Gemfile", "w") do |file| - file.puts xml_content + def check_vars_ips_for_floating + ips = [START_IP, END_IP, GATEWAY_IP] + # Check if each IPs are valid + ips.each do |ip| + begin + IPAddr.new(ip) + rescue + puts "IP (#{ip}) is not valid or nil!\nStopping now...".red + exit 1 + end + end + ip_start = IPAddr.new START_IP + ip_end = IPAddr.new END_IP + if ip_start >= ip_end + puts "START_IP (#{ip_start}) should start before END_IP (#{ip_end})! Please fix!" + exit 1 end - system("bundle install") end def check_vars(variables) + # Check if the variables aren't empty in 'vars' file. + # If a value is missing, ask the user to enter it now. vars=[] variables.each do |name, var| if var.empty? @@ -173,39 +162,40 @@ def check_vars(variables) end def get_rundeck_key - rundeck_key=`sudo cat /var/lib/rundeck/.ssh/id_rsa.pub`.chomp + rundeck_key=`cat /var/lib/rundeck/.ssh/id_rsa.pub`.chomp self.class.const_set(:RUNDECK_KEY, rundeck_key) end def install_bind9(install, floating) if install == "yes" require 'erb' - system("sudo apt-get -y install bind9") - system("sudo cp kvm/templates/db.local.erb #{KVM_FOLDER}/templates/db.local.erb") - system("sudo cp kvm/templates/db.1XX.erb #{KVM_FOLDER}/templates/db.1XX.erb") + system("apt-get -y install bind9") + system("cp kvm/templates/db.local.erb #{KVM_FOLDER}/templates/db.local.erb") + system("cp kvm/templates/db.1XX.erb #{KVM_FOLDER}/templates/db.1XX.erb") if floating == "yes" - get_ip_host + # Add zone for local network IPs. ip_host=IP_HOST.to_s puts ip_host.split - third_octet=ip_host.split(".")[2] + third_byte=ip_host.split(".")[2] template = ERB.new(File.read("kvm/templates/named.conf.local.erb")) xml_content = template.result(binding) File.open("/etc/bind/named.conf.local", "w") do |file| file.puts xml_content end else - third_octet="" + # Add zone for private network (NAT) only. + third_byte="" template = ERB.new(File.read("kvm/templates/named.conf.local.erb")) xml_content = template.result(binding) File.open("/etc/bind/named.conf.local", "w") do |file| file.puts xml_content end end - system("sudo adduser rundeck bind") - system("sudo chmod 775 /etc/bind/") - system("sudo chown rundeck:bind /etc/bind/db.local") - system("sudo touch /etc/bind/db.1XX && sudo chown rundeck:bind /etc/bind/db.1XX") - system("sudo systemctl restart bind9") + system("adduser rundeck bind") + system("chmod 775 /etc/bind/") + system("chown rundeck:bind /etc/bind/db.local") + system("touch /etc/bind/db.1XX && chown rundeck:bind /etc/bind/db.1XX") + system("systemctl restart bind9") end end @@ -229,7 +219,7 @@ def stop_install end def bye - rundeck_url_full=`sudo cat /etc/rundeck/framework.properties |grep framework.server.url |awk '{print $3}'`.chomp.bold + rundeck_url_full=`cat /etc/rundeck/framework.properties |grep framework.server.url |awk '{print $3}'`.chomp.bold puts " _ ,' '. diff --git a/scripts/rd_cmd.sh b/scripts/rd_cmd.sh new file mode 100755 index 0000000..21907ac --- /dev/null +++ b/scripts/rd_cmd.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +txtbold=$(tput bold) + +case "$1" in + "kvm-control" ) + project=$(rd projects list |grep $1) + if [[ -z "$project" ]]; then + echo -e "$txtbold Creating $1 project!\n" + rd projects create -p kvm-control -- --resources.source.2.config.url=http://localhost:9980 --resources.source.2.type=url --resources.source.2.config.timeout=60 --resources.source.2.config.cache=false + fi + ;; + "kvm-control_with-Chef" ) + echo -e "Adding jobs to kvm-control!\n" + rd jobs load -r -f $2/rundeck_jobs.xml -p kvm-control + echo -e "Adding dedicated Chef jobs to kvm-control!\n" + rd jobs load -r -f $2/chef-rundeck_jobs.xml -p kvm-control + ;; + "remove_chef_jobs" ) + jobs=$(rd jobs list -p kvm-control) + if [[ $jobs == *"Docker"* ]]; then + echo -e "\n$txtbold Removing unneeded Chef Docker jobs!\n" + rd jobs purge -y -j "Docker: Delete chef-server and chef-rundeck containers" -p kvm-control + rd jobs purge -y -j "Docker: Start chef-server and chef-rundeck containers" -p kvm-control + rd jobs purge -y -j "Docker: Stop chef-server and chef-rundeck containers" -p kvm-control + rd jobs purge -y -j "Docker: Restart chef-rundeck" -p kvm-control + fi + if [[ $jobs == *"Launch"* ]]; then + echo -e "\n$txtbold Cleaning up \".Launch KVM guest\" job!\n" + rd jobs purge -y -j ".Launch KVM guest" -p kvm-control + fi + if [[ $jobs == *"KVM: Delete guest"* ]]; then + echo -e "\n$txtbold Cleaning up \"KVM: Delete guest\" job!\n" + rd jobs purge -y -j "KVM: Delete guest" -p kvm-control + fi + if [[ $jobs == *"KVM: Delete all guests"* ]]; then + echo -e "\n$txtbold Cleaning up \"KVM: Delete all guests\" job!\n" + rd jobs purge -y -j "KVM: Delete all guests" -p kvm-control + fi + if [[ $jobs == *"4.Bootstrap guest"* ]]; then + echo -e "\n$txtbold Cleaning up \"4.Bootstrap guest\" job!\n" + rd jobs purge -y -j "4.Bootstrap guest" -p kvm-control + fi + echo -e "\n$txtbold Updating kvm-control jobs!\n" + rd jobs load -r -f $2/rundeck_jobs.xml -p kvm-control + ;; + "get_first_source" ) + rd run -p kvm-control -j "Source: Add Cloud Image or ISO" -f -- -URL $2 + ;; + "docker-control" ) + project=$(rd projects list |grep -w $1) + if [[ -z "$project" ]]; then + echo -e "$txtbold Creating $1 project and jobs!\n" + rd projects create -p docker-control + rd jobs load -r -f $2/rundeck_jobs.xml -p docker-control + else + echo -e "$1 project and jobs already created!\n" + fi + ;; +esac diff --git a/scripts/templates/Gemfile.erb b/scripts/templates/Gemfile.erb deleted file mode 100644 index 2f349ea..0000000 --- a/scripts/templates/Gemfile.erb +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' - -gem 'colorize' -gem 'json' -gem '<%= gem %>' diff --git a/scripts/templates/chef-rundeck.service.erb b/scripts/templates/chef-rundeck.service.erb deleted file mode 100644 index afdd68c..0000000 --- a/scripts/templates/chef-rundeck.service.erb +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Chef Rundeck Sinatra App -After=syslog.target - -[Service] -ExecStart=/usr/local/bin/chef-rundeck -c /var/lib/rundeck/.chef/config.rb -e development -u ubuntu -P /tmp/chef-rundeck.pid -w https://<%= Installer::IP_HOST %>:<%= CHEF_PORT %> -User=rundeck - -[Install] -WantedBy=default.target diff --git a/vars b/vars index f87d1c8..2a4f7b2 100644 --- a/vars +++ b/vars @@ -8,16 +8,16 @@ DATA_FOLDER="/srv/mission_control" KVM_FOLDER=DATA_FOLDER + "/kvm-control" DOCKER_FOLDER=DATA_FOLDER + "/docker-control" -RUNDECK_VERSION="2.7.3-1" +RUNDECK_VERSION="2.8.2-1" DATABASE_NAME="mission_control" MYSQL_PASSWORD="mcpasswd" DB_KVM_TABLE="kvm_guests" -# Is this server running in a public cloud? (i.e Is this server reachable directly from the Internet? AWS/GoogleCloud/Rackspace) +# Is this server running in a public cloud? (i.e Is this server reachable directly from the Internet? EC2/GoogleCloud/Azure/Rackspace) # yes OR no CLOUD_SERVER="no" # Which interface will be used to reach Rundeck? # NOTE: must be br0 is you are going to assign static Floating IPs to KVM guests! -INTERFACE_OUT="eth0" +INTERFACE_OUT="enp0s25" #_____________ #KVM variables @@ -32,14 +32,14 @@ BIND9="yes" #=> FLOATING IP <= # Disregard if you are just going to launch NAT'ed KVM guests. -# Floating IP range (e.i 192.168.0.1 to 192.168.0.254) +# Floating IP range (i.e 192.168.0.1 to 192.168.0.254) START_IP="" END_IP="" GATEWAY_IP="" -#_______________ -#Docker variable -#--------------- +#________________ +#Docker variables +#---------------- CHEF_SERVER_CONTAINER_NAME="chef-server" CHEF_SERVER_CONTAINER_IP="172.18.0.10" CHEF_PORT="443"