├── .gitignore ├── README.md ├── Vagrantfile ├── config └── .gitkeep ├── datastore_load └── .gitkeep ├── packs_dev └── .gitkeep ├── scripts └── install_st2.sh └── test.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant* 2 | configs/* 3 | datastore_load/* 4 | packs_dev/* 5 | .idea/* 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # st2vagrant 2 | 3 | Setup [StackStorm](https://www.stackstorm.com/product) (`st2`) on your laptop with Vagrant and 4 | VirtualBox, so you can play with it locally and develop integration and automation 5 | [packs](https://docs.stackstorm.com/latest/packs.html). 6 | 7 | If you are fluent with [Vagrant](https://www.vagrantup.com/docs/getting-started), you know where to 8 | look and what to do. If you are new to Vagrant, just follow along with step-by-step instructions 9 | below. 10 | 11 | 12 | ## Pre-requisites 13 | * [Install git](https://git-scm.com/downloads) (duh!). You may not have it if you're on Windows. 14 | 15 | * Install recent version of [Vagrant](https://www.vagrantup.com/docs/installation/) 16 | (v1.8.1 at the time of writing). For those unfortunate Windows users: [How to use Vagrant on Windows](http://tech.osteel.me/posts/2015/01/25/how-to-use-vagrant-on-windows.html) may help. 17 | 18 | * Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads) (version 5.0 and up), and 19 | VirtualBox Extension packs ([follow instructions for Extension packs 20 | here](https://www.virtualbox.org/manual/ch01.html#intro-installing)). 21 | 22 | * Note. Problems have been found using VirtualBox 5.1 with RockyLinux 8, which were resolved 23 | using version 6.1. 24 | 25 | 26 | ## Simple installation 27 | 28 | Clone the st2vagrant repo, and start up Vagrant: 29 | 30 | ```bash 31 | git clone https://github.com/StackStorm/st2vagrant.git 32 | cd st2vagrant 33 | vagrant up 34 | ``` 35 | 36 | This command will download a vagrant box, create a virtual machine, and start a script to provision 37 | the most recent unstable version of StackStorm. You will see a lot of text, some of that may be red, 38 | but not to worry, it's normal. After a while, you should see a large `ST2 OK`, which means that 39 | installation successful and a VM with StackStorm is ready to play. Log in to VM, and fire some st2 40 | commands: 41 | 42 | ```bash 43 | vagrant ssh 44 | st2 --version 45 | st2 action list 46 | ``` 47 | 48 | The WebUI is available at https://192.168.56.20. The default st2admin user credentials are in 49 | [Vagrantfile](Vagrantfile), usually `st2admin:Ch@ngeMe`. 50 | 51 | You are in business! Go to [QuickStart](https://docs.stackstorm.com/start.html) and follow along. 52 | 53 | To configure ChatOps, review and edit `/opt/stackstorm/chatops/st2chatops.env` configuration file 54 | to point to Chat Service you are using. See details in "Setup ChatOps" section in installation 55 | docs for your OS (e.g, [here is one for Ubuntu](https://docs.stackstorm.com/install/rhel7.html#setup-chatops)). 56 | 57 | The Brocade Workflow Composer bits are not yet installed; to add them and get Workflow Designer, RBAC, and LDAP, 58 | follow these [instructions to obtain a license key and 59 | install BWC](https://docs.stackstorm.com/install/bwc.html). 60 | 61 | If something went wrong, jump to [Troubleshooting](https://github.com/StackStorm/st2vagrant#common-problems-and-solutions) section below. 62 | 63 | 64 | ## Customize your st2 installation 65 | 66 | Environment variables can be used to enable or disable certain features of the StackStorm installation: 67 | 68 | * `RELEASE` - `stable` for the latest stable release, or `unstable` for a current version from dev trunk. DEFAULT: `unstable` 69 | * `VAGRANT_HOSTNAME` - the hostname to give the VM. DEFAULT: `st2vagrant` 70 | * `BOX` - the Vagrant base box to use. DEFAULT: `ubuntu/bionic64` 71 | * `ST2USER` - Username for st2. DEFAULT: st2admin 72 | * `ST2PASSWORD` - Password for st2. DEFAULT: `Ch@ngeMe` 73 | * `VERSION` - the version of StackStorm to install: `3.2` 74 | 75 | Set the variables by pre-pending them to `vagrant up` command. In the example below, it will install 76 | a version of st2 from development trunc, and set password to `secret`: 77 | 78 | ```RELEASE="unstable" ST2PASSWORD="secret" vagrant up``` 79 | 80 | To evaluate StackStorm on supported OS flavors, consider using the boxes we use 81 | [for testing `st2`](https://github.com/StackStorm/st2-test-ground/blob/master/Vagrantfile) 82 | for best results: 83 | 84 | * ubuntu/focal64 for Ubuntu 20.04 85 | * ubuntu/bionic64 for Ubuntu 18.04 (default) 86 | * ubuntu/xenial64 for Ubuntu 16.04 87 | * ubuntu/trusty64 for Ubuntu 14.04 88 | * bento/centos-6.7 for CentOS 6.7 89 | * centos/7 for CentOS 7 90 | * rockylinux/8 for RockyLinux 8 91 | 92 | Examples: 93 | 94 | ```bash 95 | BOX="centos/7" vagrant up 96 | ``` 97 | 98 | ```bash 99 | BOX=centos/7 RELEASE=stable vagrant up 100 | ``` 101 | 102 | Or use your favorite vagrant box. **Note that StackStorm installs from native Linux packages, which 103 | are built for following OSes only. Make make sure the OS flavor of your box is one of the 104 | following:** 105 | 106 | * Ubuntu 20.04 (Focal Fossa) 107 | * **Ubuntu 18.04 (Bionic Beaver)** (default) 108 | * Ubuntu 16.04 (Xenial Xerus) 109 | * Ubuntu 14.04 (Trusty Tahr) 110 | 111 | * CentOS 7 / RHEL 7 112 | * RockyLinux 8 / RHEL 8 113 | 114 | ### Synced folders 115 | 116 | **Warning:** 117 | 118 | If you mount the above synced folder prior to ST2 installation, the installation may fail due to 119 | synced folders not supporting ownership and/or permissions changes by default. 120 | Also, notice that if you enable the above synced folder, it will *hide* the vagrant box's local 121 | /opt/stackstorm/packs folder. You will need to move the core packages here for ST2 to run properly. 122 | 123 | By the time you read this hint, your VM is most likely already up and running. Not to worry: just 124 | uncomment the above mentioned line in your `Vagrantfile` and run `vagrant reload --no-provision`. 125 | This will restart the VM and apply the new config without running the provision part, so you won't 126 | reinstall st2. Vagrant will however ask you for your laptop password to sync the folders. 127 | 128 | For details on NFS refer: https://www.vagrantup.com/docs/synced-folders/nfs.html 129 | 130 | To learn about packs and how to work with them, see 131 | [StackStorm documentation on packs!](https://docs.stackstorm.com/latest/packs.html) 132 | 133 | #### Using the vmware_desktop provider 134 | 135 | If you wish to startup a VM with the VMWare Workstation or VMWare Fusionproviders, 136 | eg: vmware_desktop , you will need to specify `SYNCED_FOLDER_OPTIONS=vmware` when 137 | running `vagrant up`. 138 | 139 | ``` 140 | SYNCED_FOLDER_OPTIONS=vmware BOX=bento/centos-7.6 RELEASE=stable vagrant up 141 | ``` 142 | 143 | If you have multiple providers installed, to force the vmwware_desktop provider: 144 | 145 | ```bash 146 | VAGRANT_DEFAULT_PROVIDER=vmware_desktop SYNCED_FOLDER_OPTIONS=vmware BOX=bento/centos-7.6 RELEASE=stable vagrant up 147 | ``` 148 | 149 | Only the bento/centos-7.6 has been tested. This vagrant box reliably ships with VMWare 150 | tools installed for synced folders. 151 | 152 | The options to `synced_folder` are the following for the VM provider: 153 | 154 | | Provider | Synced folder options | 155 | | -------------------- | --------------------------------------------- | 156 | | VMWare | `**{}` (no options) | 157 | | Virtualbox (default) | `**{nfs: true, mount_options: ["nfsvers=3"]}` | 158 | 159 | #### Using the libvirt provider (KVM) 160 | 161 | If you want to run the the VM with KVM/libvirt simply do: 162 | 163 | ``` bash 164 | BOX=generic/ubuntu1804 vagrant up --provider libvirt 165 | BOX=centos/7 vagrant up --provider libvirt 166 | BOX=rockylinux/8 vagrant up --provider libvirt 167 | ``` 168 | 169 | #### Common synced folders for Pack development 170 | 171 | Playing with StackStorm ranges from creating rules and workflows, to turning your scripts into 172 | actions, to writing custom sensors. And all of that involves working with files under 173 | `/opt/stackstorm/packs` on `st2vagrant` VM. One can do it via SSH, but with all your favorite tools 174 | already set up on your laptop, it's convenient to hack files and work with `git` there on the host. 175 | 176 | You can create your pack directories under `st2vagrant/` on your host. Vagrant automatically maps 177 | it's host directory to `/vagrant` directory on the VM, where you can symlink files and dirs to 178 | desired locations. 179 | 180 | Alternatively, you can specify a comma-separated list of common synced folders in the the 181 | `SYNCED_FOLDERS` environment variable to mount them in the guest VM. 182 | 183 | ```bash 184 | SYNCED_FOLDERS=packs,datastore_load vagrant up 185 | ``` 186 | 187 | Available common synced folders are: 188 | 189 | | Host folder | Guest folder | 190 | | ------------------ | -------------------------------- | 191 | | `.` | `/vagrant` | 192 | | `./config` | `/opt/stackstorm/config` | 193 | | `./packs` | `/opt/stackstorm/packs` | 194 | | `./packs_dev` | `/opt/stackstorm/packs_dev` | 195 | | `./datastore_load` | `/opt/stackstorm/datastore_load` | 196 | 197 | #### Custom synced folders 198 | 199 | If you would like to use synced folders that are not one of the common synced folders, you can 200 | specify a comma-separated list of custom folders to sync in the `CUSTOM_SYNCED_FOLDERS` 201 | environment variable. 202 | 203 | There are different ways to specify synced folders. You can specify just the host folder, which 204 | will be mounted to `/home/vagrant/{folder}` within the guest, using the mount settings specified 205 | with `SYNCED_FOLDER_OPTIONS`. 206 | 207 | ```bash 208 | CUSTOM_SYNCED_FOLDERS=../st2client.js,../hubot-stackstorm vagrant up 209 | ``` 210 | 211 | will mean `../st2client.js` and `../hubot-stackstorm` will be mounted into 212 | `/home/vagrant/st2client.js` and `/home/vagrant/hubot-stackstorm`, respectively, in the guest. 213 | 214 | You can also specify the host folder as well as the guest folder, by separating them with a `:`: 215 | 216 | ```bash 217 | CUSTOM_SYNCED_FOLDERS=../st2client.js:/custom/dir/st2client.js,../hubot-stackstorm:/custom/dir/hubot-stackstorm vagrant up 218 | ``` 219 | 220 | This will mount the directories into `/custom/dir/st2client.js` and `/custom/dir/hubot-stackstorm`, 221 | respectively, using the default mount settings specified with `SYNCED_FOLDER_OPTIONS`. 222 | 223 | Finally, you can specify mount options individually for each synced folder by adding them after 224 | another `:`: 225 | 226 | ```bash 227 | CUSTOM_SYNCED_FOLDERS=../st2client.js:/custom/dir/st2client.js:{disabled:true},../hubot-stackstorm:/custom/dir/hubot-stackstorm:{custom_option:["nfsvers=3"]} vagrant up 228 | ``` 229 | 230 | The options will be `eval()`ed (as a Ruby snippet) within the `Vagrantfile`, then used in a double 231 | splat argument. This means that you can specify all options to the `vm.synced_folder` function 232 | in these options. 233 | 234 | #### Advanced Pack Development Synced Folder Workflow Strategy 235 | 236 | One of the common use cases is pack development. In order to streamline a persistent local 237 | development environment, the following approach could be used: 238 | 239 | **Warning** 240 | 241 | Syncing the config directory before ST2 install will cause the installation to fail due to permissions. There is 242 | probably a workaround -> if you know it open an issue and let us know. 243 | 244 | 1. Synced folders you may wish to utilize to speed up setup of Vagrant box: 245 | 246 | * `config` --> synced to `/opt/stackstorm/config` 247 | * `datastore_load` --> synced to `/opt/stackstorm/datastore_load` 248 | * `packs_dev` --> synced to `/opt/stackstorm/packs_dev` 249 | 250 | 2. Folder usage: 251 | 252 | * `config` folder: You can persist pack configs such as `aws.yaml` or `jira.yaml` in this folder and they will be 253 | present after vagrant up 254 | * `datastore_load`: Use this folder to store a json file that you would import to the datastore using 255 | `st2 key load /opt/stackstorm/datastore_load/mykeystoredata.json` 256 | * `packs_dev`: Use this folder to iterate on packs you are developing. After you commit your changes you can install 257 | the pack in your Vagrant box: 258 | - `cd /opt/stackstorm/packs_dev/YOUR_PACK_DIRECTORY` 259 | - `st2 pack install file:///$PWD [--python3]` 260 | 261 | 3. Additional information 262 | 263 | * This repo includes .gitignore entries for the 3 directories described above. 264 | * This approach remove any installation conflicts, and prevents confusion of installing dev packs into ST2, since 265 | the `st2 pack install` command will create a clone of the pack in `/opt/stackstorm/packs` directory. 266 | 267 | See the `NFS Advanced Pack Dev Approach` and `VMWARE HGFS Advanced Pack Dev Approach` in the Vagrantfile for synced 268 | folder configs that follow this strategy. 269 | 270 | 271 | ## Manual installation 272 | 273 | To master StackStorm and understand how things are wired together, we strongly encourage you to 274 | [eventually] install StackStorm manually, following 275 | [installation instructions](https://docs.stackstorm.com/install/). You can still 276 | benefit from this Vagrantfile to get the Linux VM up and running: follow instructions to 277 | install Vagrant & VirtualBox to get a Linux VM, and simply comment out the 278 | `st2.vm.provision "shell"...` section in your `Vagrantfile` before running `vagrant up`. 279 | 280 | 281 | ## Common problems and solutions 282 | 283 | #### IP Conflicts 284 | 285 | In the event you receive an error related to IP conflict, Edit the `private_neworks` address in `Vagrantfile`, and adjust the third octet to a non-conflicting value. For example: 286 | 287 | ``` 288 | # Configure a private network 289 | st2.vm.network :private_network, ip: "192.168.56.20" 290 | ``` 291 | 292 | 293 | #### Mounts 294 | 295 | Sometimes after editing or adding NFS mounts via `config.vm.synced_folder`,and firing `vagrant up` or `vagrant reload`, you may see this: 296 | 297 | ``` 298 | ==> st2express: Exporting NFS shared folders... 299 | NFS is reporting that your exports file is invalid. Vagrant does 300 | this check before making any changes to the file. Please correct 301 | the issues below and execute "vagrant reload": 302 | 303 | exports:3: path contains non-directory or non-existent components: /Volumes/Repo/st2 304 | exports:3: path contains non-directory or non-existent components: /Volumes/Repo/st2contrib 305 | exports:3: path contains non-directory or non-existent components: /Volumes/Repo/st2incubator 306 | exports:3: no usable directories in export entry 307 | exports:3: using fallback (marked offline): /Volumes/Repo 308 | ``` 309 | FIX: Remove residuals from `/etc/exports` file on the host machine, and do `vagrant reload` again. 310 | 311 | 312 | ## Using st2vagrant for release testing 313 | 314 | Creates a box from a specific development version of code: 315 | 316 | ``` bash 317 | BOX=centos/7 RELEASE=unstable VERSION=3.1dev vagrant up 318 | ``` 319 | 320 | ## Support 321 | 322 | Please follow [guidelines](https://docs.stackstorm.com/troubleshooting/ask_for_support.html) for support if none of the [self troubleshooting guides](https://docs.stackstorm.com/troubleshooting/index.html) do not help! Ask community on Slack at stackstorm-community.slack.com channel ([register here first](https://stackstorm.com/community-signup)). 323 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | # 4 | # To force a specific provider set the VAGRANT_DEFAULT_PROVIDER environment variable. 5 | # Vagrant defaults to virtual box if you have it installed 6 | # eg: VAGRANT_DEFAULT_PROVIDER=libvirt 7 | # eg: VAGRANT_DEFAULT_PROVIDER=virtualbox 8 | # eg: VAGRANT_DEFAULT_PROVIDER=vmware_deskop 9 | 10 | # The OS to spin up 11 | # Default: ubuntu/bionic64 12 | # Examples: 13 | # BOX=ubuntu/trusty64 14 | # BOX=ubuntu/xenial64 15 | # BOX=ubuntu/bionic64 16 | # BOX=ubuntu/focal64 17 | # BOX=centos/6 18 | # BOX=centos/7 19 | # BOX=rockylinux/8 20 | # 21 | # # VMWare 22 | # # Below box tested with vmware_fusion provider, vmware tools installed properly 23 | # BOX=bento/centos-7.6 24 | # 25 | # # Libvirt 26 | # # The ubuntu/ boxes aren't built for libvirt, so you'll need to use the generic/ or 27 | # # bento/ boxes. 28 | # # The normal centos/6, centos/7, rockylinux/8 all work fine on libvirt. 29 | # BOX=generic/ubuntu1604 30 | # BOX=generic/ubuntu1804 31 | # BOX=centos/6 32 | # BOX=centos/7 33 | # BOX=rockylinux/8 34 | vm_box = ENV['BOX'] ? ENV['BOX'] : 'ubuntu/bionic64' 35 | 36 | # The hostname of the Vagrant VM 37 | # Default: st2vagrant 38 | # Examples: 39 | # VAGRANT_HOSTNAME=st2vagrant-rhel7 40 | # VAGRANT_HOSTNAME=rhel7-testing 41 | # 42 | # Note, we specifically do NOT name this "HOSTNAME" because that is a 43 | # common environment variable and will set the vagrant VM's hostname to the 44 | # same as the hypervisor host running the vagrant VM. 45 | vm_hostname = ENV['VAGRANT_HOSTNAME'] ? ENV['VAGRANT_HOSTNAME'] : 'st2vagrant' 46 | 47 | # The IP address to assign to the VM 48 | # Default: 192.168.56.20 49 | # Examples: 50 | # VM_IP=192.168.1.4 51 | vm_ip = ENV['VM_IP'] ? ENV['VM_IP'] : '192.168.56.20' 52 | 53 | # The ST2 user 54 | # Default: st2admin 55 | # Example: 56 | # ST2USER=st2user 57 | st2user = ENV['ST2USER'] ? '-u "' + ENV['ST2USER'] + '"': '-u "st2admin"' 58 | 59 | # The ST2 user password 60 | # Default: Ch@ngeMe 61 | # Example: ST2PASSWORD=secret-tunnel/secret-tunnel/through-the-mountain/secret-secret-tunnel 62 | st2passwd = ENV['ST2PASSWORD'] ? '-p "' + ENV['ST2PASSWORD'] + '"' : '-p "Ch@ngeMe"' 63 | 64 | # Which release channel (stable or unstable to use) 65 | # Default: unstable 66 | # RELEASE=stable 67 | # RELEASE=unstable 68 | release = ENV['RELEASE'] ? '-r "' + ENV['RELEASE'] + '"' : '-r unstable' 69 | 70 | # Which release channel (staging or production to use) 71 | # Default: (empty string, eg: production) 72 | # REPO_TYPE=staging 73 | repo_type = ENV['REPO_TYPE'] ? '-t ' + ENV['REPO_TYPE'] : '' 74 | 75 | # Which version of the package to install - must be specified in x.y.z format 76 | # or X.Ydev 77 | # Default: (empty string, meaning latest) 78 | # VERSION=3.1dev 79 | # VERSION=3.2.0 80 | version = ENV['VERSION'] ? '-v "' + ENV['VERSION'] + '"' : '' 81 | 82 | # Build source - used to install packages from a specific CircleCI build 83 | # Default: Packagecloud 84 | # Examples: 85 | # DEV=st2/5017 86 | # DEV=mistral/1012 87 | # DEV=st2-packages/3021 88 | dev = ENV['DEV'] ? '-d ' + ENV['DEV'] : '' 89 | 90 | # The branch of st2-packages or bwc-installer to pull and use 91 | # Default: master 92 | # Examples: 93 | # BRANCH=master 94 | # BRANCH=yum-exclude-nginx 95 | branch = ENV['BRANCH'] ? '-b "' + ENV['BRANCH'] + '"' : '' 96 | 97 | # A comma-separated list of synced folder options, specified as key/value pairs 98 | # Option values are interpreted as Ruby code 99 | # Default: (empty) 100 | # Examples: 101 | # SYNCED_FOLDER_OPTIONS=vmware # -> {} (no options) 102 | # SYNCED_FOLDER_OPTIONS='' # -> {nfs:true,mount_options:["nfsvers=3"]} (Virtualbox) 103 | default_sf_options = {} 104 | all_sf_options = ENV['SYNCED_FOLDER_OPTIONS'] == 'vmware' ? [] : ['nfs:true', 'mount_options:["nfsvers=3"]'] 105 | all_sf_options.each do |opt| 106 | opt_name, opt_value = opt.split(':') 107 | opt_value = eval(opt_value) 108 | default_sf_options[opt_name.to_sym] = opt_value 109 | end 110 | 111 | # A comma-separated list of common folders to sync 112 | # Available common folders: 113 | # . /vagrant 114 | # config /opt/stackstorm/config 115 | # packs_dev /opt/stackstorm/packs_dev 116 | # packs /opt/stackstorm/packs 117 | # datastore_load /opt/stackstorm/datastore_load 118 | # 119 | # Default: '' 120 | # Examples: 121 | # SYNCED_FOLDERS='.' 122 | # SYNCED_FOLDERS='.,config' 123 | # SYNCED_FOLDERS='.,config,packs_dev,packs,datastore_load' 124 | vm_synced_folders = [] 125 | all_synced_folders = ENV['SYNCED_FOLDERS'] ? ENV['SYNCED_FOLDERS'].split(',') : [] 126 | all_synced_folders_map = { 127 | '.'=> ['/vagrant', disabled: true], 128 | 'config'=> ['/opt/stackstorm/config', {}], 129 | 'packs_dev'=> ['/opt/stackstorm/packs_dev', {}], 130 | 'packs'=> ['/opt/stackstorm/packs', {}], 131 | 'datastore_load'=> ['/opt/stackstorm/datastore_load', {}], 132 | } 133 | all_synced_folders.each do |sf| 134 | vm_synced_folder = all_synced_folders_map.fetch(sf, nil) 135 | next if not vm_synced_folder 136 | 137 | vm_synced_folders.push [sf, vm_synced_folder[0], default_sf_options.merge(vm_synced_folder[1])] 138 | end 139 | 140 | # A comma-separated list of folder pairs/triples to sync 141 | # Each folder pair is specified as host_folder:guest_folder 142 | # Each folder triple is specified as host_folder:guest_folder:shared_folder_options 143 | # Relative host folders are specified relative to this Vagrantfile 144 | # Shared folder options are evaluated as Ruby code 145 | # Default: '' 146 | # Examples: 147 | # CUSTOM_SYNCED_FOLDERS='../st2client.js,../hubot-stackstorm,../st2chatops' 148 | # CUSTOM_SYNCED_FOLDERS='../st2client.js:/home/vagrant/st2client.js,'\ 149 | # '../hubot-stackstorm:/home/vagrant/hubot-stackstorm,'\ 150 | # '../st2chatops:/home/vagrant/st2chatops,'\ 151 | # '../exchange:/home/vagrant/exchange,'\ 152 | # '../st2tests:/home/vagrant/st2tests'\ 153 | # '../st2tests:/home/vagrant/st2web' 154 | # CUSTOM_SYNCED_FOLDERS='../st2client.js:/home/vagrant/st2client.js:'\ 155 | # '../hubot-stackstorm:/home/vagrant/hubot-stackstorm,' 156 | all_custom_synced_folders = ENV['CUSTOM_SYNCED_FOLDERS'] ? ENV['CUSTOM_SYNCED_FOLDERS'].scan(/([^:,]+)(?::([^:,]+))?(?::(?:((?:\{[^:}]+?\})|(?:\[[^:\]]+?\]))))?/) : [] 157 | all_custom_synced_folders.each do |sfpair| 158 | host_folder, guest_folder, sf_options = sfpair 159 | guest_folder = guest_folder ? guest_folder : "/home/vagrant/#{File.basename(host_folder)}" 160 | sf_options = sf_options ? eval(sf_options) : {} 161 | 162 | vm_synced_folders.push [host_folder, guest_folder, default_sf_options.merge(sf_options)] 163 | end 164 | 165 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 166 | # Minimum Vagrant Version 167 | Vagrant.require_version ">= 2.2.0" 168 | VAGRANTFILE_API_VERSION = "2" 169 | 170 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 171 | config.vm.define "#{vm_hostname}" do |st2| 172 | # Global Box details 173 | st2.vm.box = "#{vm_box}" 174 | st2.vm.hostname = "#{vm_hostname}" 175 | 176 | # Box Specifications 177 | # VirtualBox 178 | st2.vm.provider :virtualbox do |vb| 179 | vb.gui = false # Change to true to launch console 180 | vb.name = "#{vm_hostname}" 181 | vb.memory = 4096 182 | vb.cpus = 2 183 | end 184 | 185 | # VMWare Desktop (fusion/workstation) 186 | ["vmware_fusion", "vmware_workstation"].each do |provider| 187 | st2.vm.provider provider do |vmw, override| 188 | vmw.gui = false # Change to true to launch console 189 | vmw.vmx["ethernet0.virtualDev"] = "vmxnet3" 190 | vmw.vmx["memsize"] = 4096 191 | vmw.vmx["numvcpus"] = 2 192 | # Do not overwrite pci-slot number (https://www.vagrantup.com/docs/vmware/boxes.html#making-compatible-boxes) 193 | config.vm.provider provider do |vmware| 194 | vmware.whitelist_verified = true 195 | end 196 | end 197 | end 198 | 199 | # KVM / libvirt 200 | st2.vm.provider :libvirt do |lv, override| 201 | lv.host = vm_hostname 202 | lv.memory = 4096 203 | lv.cpus = 2 204 | lv.uri = "qemu:///system" 205 | lv.storage_pool_name = "images" 206 | # use a different network than the virtualbox provider so we can run virtualbox 207 | # and libvirt on the same machine 208 | override.vm.network :private_network, ip: "192.168.26.20" 209 | end 210 | 211 | vm_synced_folders.each do |host_folder, guest_folder, sf_options| 212 | st2.vm.synced_folder(host_folder, guest_folder, **sf_options) 213 | end 214 | 215 | # Configure a private network 216 | st2.vm.network :private_network, ip: "#{vm_ip}" 217 | 218 | # Public (bridged) network may come handy for external access to VM (e.g. sensor development) 219 | # See https://www.vagrantup.com/docs/networking/public_network.html 220 | # st2.vm.network "public_network", bridge: 'en0: Wi-Fi (AirPort)' 221 | 222 | # Start shell provisioning. 223 | st2.vm.provision "shell" do |s| 224 | s.path = "scripts/install_st2.sh" 225 | s.args = "#{st2user} #{st2passwd} #{release} #{repo_type} #{dev} #{branch} #{version}" 226 | s.privileged = false 227 | end 228 | end 229 | end 230 | -------------------------------------------------------------------------------- /config/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StackStorm/st2vagrant/7ae13af9ac6ef2c4ca44984c640a8052e1d57b2b/config/.gitkeep -------------------------------------------------------------------------------- /datastore_load/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StackStorm/st2vagrant/7ae13af9ac6ef2c4ca44984c640a8052e1d57b2b/datastore_load/.gitkeep -------------------------------------------------------------------------------- /packs_dev/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StackStorm/st2vagrant/7ae13af9ac6ef2c4ca44984c640a8052e1d57b2b/packs_dev/.gitkeep -------------------------------------------------------------------------------- /scripts/install_st2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | echo "$@" 6 | 7 | while getopts "u:p:r:t:d:b:v:" option; do 8 | case "${option}" in 9 | u) ST2_USER=${OPTARG};; 10 | p) ST2_PASSWORD=${OPTARG};; 11 | r) RELEASE=${OPTARG};; 12 | t) REPO_TYPE=${OPTARG};; 13 | d) DEV="--dev=${OPTARG}";; 14 | b) BRANCH=${OPTARG};; 15 | v) VERSION=${OPTARG};; 16 | esac 17 | done 18 | 19 | 20 | # Select between recent stable (e.g. 1.4) or recent unstable (e.g. 1.5dev) 21 | if [[ "$RELEASE" == "stable" || "$RELEASE" == "unstable" ]]; then 22 | RELEASE_FLAG="--${RELEASE}" 23 | else 24 | echo "Use 'stable' for recent stable release, or 'unstable' to live on the edge, not '$RELEASE'." 25 | exit 2 26 | fi 27 | 28 | if [[ "$REPO_TYPE" == "staging" ]]; then 29 | REPO_TYPE="--staging" 30 | fi 31 | 32 | if [[ -n "$VERSION" ]]; then 33 | VERSION_FLAG="--version=${VERSION}" 34 | 35 | # If BRANCH isn't specified 36 | # But VERSION is a specified *released* version 37 | if [[ -z "$BRANCH" && "$VERSION" =~ ^[[:digit:]]{1,}\.[[:digit:]]{1,}\.[[:digit:]]{1,} ]]; then 38 | # Default the st2-packages branch to the version branch 39 | BRANCH="v$(echo $VERSION | sed 's/^\([[:digit:]]*\.[[:digit:]]*\).*/\1/')" 40 | fi 41 | fi 42 | 43 | # Default BRANCH to master 44 | BRANCH="${BRANCH:-master}" 45 | 46 | BRANCH_FLAG="--force-branch=$BRANCH" 47 | 48 | 49 | echo "*** Let's install some net tools ***" 50 | 51 | DEBTEST=$(lsb_release -a 2> /dev/null | grep Distributor | awk '{print $3}') # Ubuntu 52 | DEBCODENAME=$(lsb_release -a 2> /dev/null | grep Codename | awk '{print $2}') # xenial|bionic 53 | RHTEST='' 54 | 55 | echo $DEBTEST 56 | echo $DEBCODENAME 57 | # For ST2 v3.4 on Ubuntu Xenial 58 | if [[ "$DEBTEST" == "Ubuntu" && "$DEBCODENAME" == "xenial" ]]; then 59 | if [[ -z "$VERSION" || "$VERSION" == 3.4* ]]; then 60 | # Add a flag to automatically install and use the Python 3 repository from the deadsnakes PPA 61 | XENIAL_ST2_3_4_PYTHON3_FLAG="--u16-add-insecure-py3-ppa" 62 | fi 63 | fi 64 | 65 | if [[ -e /etc/redhat-release ]]; then 66 | RHTEST=$(cat /etc/redhat-release 2> /dev/null | sed -e "s~\(.*\)release.*~\1~g") 67 | RHMAJVER=$(cat /etc/redhat-release | sed 's/[^0-9.]*\([0-9.]\).*/\1/') 68 | fi 69 | 70 | if [[ -n "$RHTEST" ]]; then 71 | echo "*** Detected Distro is ${RHTEST} ***" 72 | hash curl 2>/dev/null || { sudo yum install -y curl; sudo yum install -y nss; } 73 | sudo yum update -y curl nss 74 | elif [[ -n "$DEBTEST" ]]; then 75 | echo "*** Detected Distro is ${DEBTEST} ***" 76 | sudo apt-get update 77 | sudo apt-get install -y curl 78 | else 79 | echo "Unknown Operating System." 80 | echo "See list of supported OSes: https://github.com/StackStorm/st2vagrant/blob/master/README.md" 81 | exit 2 82 | fi 83 | 84 | echo "*** Let's install some dev tools ***" 85 | 86 | if [[ -n "$RHTEST" ]]; then 87 | sudo yum install -y epel-release 88 | sudo yum install -y python3 89 | sudo yum install -y python3-pip git 90 | elif [[ -n "$DEBTEST" ]]; then 91 | sudo apt-get install -y python3 python3-pip git 92 | fi 93 | python3 --version 94 | 95 | echo "*** Let's install some python tools ***" 96 | sudo -H pip3 install --upgrade pip\<21 97 | sudo -H pip3 install --upgrade virtualenv==16.6.0 98 | 99 | echo "*** Let's install StackStorm ***" 100 | 101 | echo "--user=$ST2_USER --password=$ST2_PASSWORD $DEV $BRANCH_FLAG $RELEASE_FLAG $VERSION_FLAG $XENIAL_ST2_3_4_PYTHON3_FLAG" 102 | curl -sSL https://raw.githubusercontent.com/StackStorm/st2-packages/$BRANCH/scripts/st2_bootstrap.sh | bash -s -- --user=$ST2_USER --password=$ST2_PASSWORD $DEV $BRANCH_FLAG $RELEASE_FLAG $REPO_TYPE $VERSION_FLAG $XENIAL_ST2_3_4_PYTHON3_FLAG 103 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | E_PARAM_ERR=98 4 | E_ASSERT_FAILED=99 5 | 6 | # http://tldp.org/LDP/abs/html/debugging.html#ASSERT 7 | ####################################################################### 8 | assert () # If condition false, 9 | { #+ exit from script 10 | #+ with appropriate error message. 11 | 12 | set -eux 13 | 14 | if [ -z "$2" ] # Not enough parameters passed 15 | then #+ to assert() function. 16 | return $E_PARAM_ERR # No damage done. 17 | fi 18 | 19 | lineno=$2 20 | 21 | if [[ ! $1 ]] 22 | then 23 | echo "Assertion failed:" 24 | echo "\"$1\"" 25 | echo "File \"$0\", line $lineno" # Give name of file and line number. 26 | exit $E_ASSERT_FAILED 27 | # else 28 | # return 29 | # and continue executing the script. 30 | fi 31 | 32 | set +eux 33 | } # Insert a similar assert() function into a script you need to debug. 34 | ####################################################################### 35 | 36 | 37 | 38 | echo '================ Testing COMMUNITY VERSION ================' 39 | 40 | echo '---------------- Test: default options ---------------------' 41 | 42 | unset BOX BRANCH DEV HOSTNAME RELEASE REPO_TYPE ST2USER ST2PASSWORD VERSION VM_IP 43 | vagrant destroy 44 | 45 | # Default options 46 | vagrant up 47 | 48 | sleep 10 49 | 50 | # Check the OS 51 | DEFAULT_ETC_ISSUE_VALUE=$(vagrant ssh --command "printf \"\$(sed 's| \\\\l||' /etc/issue)\"" | tr -d '\r') 52 | assert "$? -eq 0" $LINENO 53 | assert "'$DEFAULT_ETC_ISSUE_VALUE' == Ubuntu 16.04*" $LINENO 54 | 55 | # Check the hostname 56 | DEFAULT_HOSTNAME_VALUE=$(vagrant ssh --command "hostname" | tr -d '\r\n') 57 | assert "$? -eq 0" $LINENO 58 | assert "'$DEFAULT_HOSTNAME_VALUE' = st2vagrant" $LINENO 59 | 60 | # Check the IP 61 | vagrant ssh --command "ifconfig | grep -q 'inet addr:192.168.16.20 Bcast:192.168.16.255 Mask:255.255.255.0'" 62 | assert "$? -eq 0" $LINENO 63 | 64 | # Check the username and password 65 | DEFAULT_USER_LOGIN=$(vagrant ssh --command "st2 login st2admin --password 'Ch@ngeMe'") 66 | assert "$? -eq 0" $LINENO 67 | 68 | DEFAULT_USER_VALUE=$(vagrant ssh --command "st2 whoami | grep -q 'Currently logged in as \"st2admin\"'") 69 | assert "$? -eq 0" $LINENO 70 | assert "'$DEFAULT_USER_VALUE' == st2admin" $LINENO 71 | 72 | # Check the Packagecloud community repository 73 | vagrant ssh --command 'grep -qE "^deb https://packagecloud.io/StackStorm/unstable/ubuntu/ xenial main$" /etc/apt/sources.list.d/StackStorm*stable.list' 74 | assert "$? -eq 0" $LINENO 75 | 76 | # Check that installed packages are for the unstable (dev-) community version 77 | vagrant ssh --command "apt search ^st2 2>/dev/null | grep -qE '^st2.*[[:digit:]]*\.[[:digit:]]*dev\-[[:digit:]]*.*\[.*installed.*\]\$'" 78 | assert "$? -eq 0" $LINENO 79 | 80 | vagrant destroy --force 81 | 82 | 83 | echo '---------------- Test: custom vm options -------------------' 84 | 85 | # Custom options for booting the box and setting up the st2 user 86 | BOX=ubuntu/bionic64 \ 87 | HOSTNAME=st2vagrant-bionic \ 88 | VM_IP=192.168.16.40 \ 89 | ST2USER=st2customuser \ 90 | ST2PASSWORD=st2passwd \ 91 | vagrant up 92 | 93 | sleep 10 94 | 95 | # Check the OS 96 | CUSTOM_VM_ETC_ISSUE_VALUE=$(\ 97 | BOX=ubuntu/bionic64 \ 98 | HOSTNAME=st2vagrant-bionic \ 99 | VM_IP=192.168.16.40 \ 100 | ST2USER=st2customuser \ 101 | ST2PASSWORD=st2passwd \ 102 | vagrant ssh --command "printf \"\$(sed 's| \\\\l||' /etc/issue)\"" | tr -d '\r') 103 | assert "$? -eq 0" $LINENO 104 | assert "'$CUSTOM_VM_ETC_ISSUE_VALUE' = Ubuntu 18.04*" $LINENO 105 | 106 | # Check the hostname 107 | CUSTOM_VM_HOSTNAME_VALUE=$(\ 108 | BOX=ubuntu/bionic64 \ 109 | HOSTNAME=st2vagrant-bionic \ 110 | VM_IP=192.168.16.40 \ 111 | ST2USER=st2customuser \ 112 | ST2PASSWORD=st2passwd \ 113 | vagrant ssh --command "hostname" | tr -d '\r\n') 114 | assert "$? -eq 0" $LINENO 115 | echo $CUSTOM_VM_HOSTNAME_VALUE 116 | assert "'$CUSTOM_VM_HOSTNAME_VALUE' = st2vagrant-bionic" $LINENO 117 | 118 | # Check the IP 119 | BOX=ubuntu/bionic64 \ 120 | HOSTNAME=st2vagrant-bionic \ 121 | VM_IP=192.168.16.40 \ 122 | ST2USER=st2customuser \ 123 | ST2PASSWORD=st2passwd \ 124 | vagrant ssh --command "ifconfig | grep -q 'inet addr:192.168.16.40 Bcast:192.168.16.255 Mask:255.255.255.0'" 125 | assert "$? -eq 0" $LINENO 126 | 127 | # Check the username and password 128 | CUSTOM_VM_USER_VALUE=$(\ 129 | BOX=ubuntu/bionic64 \ 130 | HOSTNAME=st2vagrant-bionic \ 131 | VM_IP=192.168.16.40 \ 132 | ST2USER=st2customuser \ 133 | ST2PASSWORD=st2passwd \ 134 | vagrant ssh --command "st2 login st2customuser --password 'st2passwd'; st2 whoami | grep -q 'Currently logged in as \"st2customuser\".'") 135 | assert "$? -eq 0" $LINENO 136 | assert "'$CUSTOM_VM_USER_VALUE' = st2customuser" $LINENO 137 | 138 | BOX=ubuntu/bionic64 \ 139 | HOSTNAME=st2vagrant-bionic \ 140 | VM_IP=192.168.16.40 \ 141 | ST2USER=st2customuser \ 142 | ST2PASSWORD=st2passwd \ 143 | vagrant destroy --force 144 | 145 | 146 | echo '---------------- Test: installation options ----------------' 147 | 148 | # Repository 149 | REPO_TYPE=staging \ 150 | RELEASE=stable \ 151 | vagrant up 152 | 153 | sleep 10 154 | 155 | # Check the Packagecloud community repository 156 | REPO_TYPE=staging \ 157 | RELEASE=stable \ 158 | vagrant ssh --command 'grep -qE "^deb https://packagecloud.io/StackStorm/staging-stable/ubuntu/ xenial main$" /dev/null | grep -qE '^st2.*[[:digit:]]*\.[[:digit:]]*\-[[:digit:]]*.*\[.*installed.*\]\$'" 165 | assert "$? -eq 0" $LINENO 166 | 167 | REPO_TYPE=staging \ 168 | RELEASE=stable \ 169 | vagrant destroy --force 170 | --------------------------------------------------------------------------------