You may want to perform special task at some specific BOSH deployment stage. For example,
BOSH os-conf release contains the jobs which could help in such case at the following BOSH deployment stages.
This KB article provides an example to utilise pre-start-script job included in os-conf release to run some commands at pre-start stage of a BOSH deployment. BOSH runtime config is also used here to apply it on specific deployments/instance groups/jobs.
BOSH instances on Tanzu Platform
1. Upload os-conf release to BOSH director
$ bosh upload-release --sha1=sha256:efcf30754ce4c5f308aedab3329d8d679f5967b2a4c3c453204c7cb10c7c5ed9 "https://bosh.io/d/github.com/cloudfoundry/os-conf-release?v=23.0.0"
2. Create BOSH runtime config to apply os-conf release job for specific BOSH instance group/deployment/job.
For example, you have the following testdep deployment in your environment.
$ bosh -d testdep vms
Using environment '#.#.#.#' as client 'ops_manager'
Task 4542. Done
Deployment 'testdep'
Instance Process State AZ IPs VM CID VM Type Active Stemcell
master/d8cf70de-####-43b47c44a019 running az1 #.#.#.# vm-547853ad-####-7c1d1d1169c0 micro true bosh-vsphere-esxi-ubuntu-jammy-go_agent/1.866
worker/7f24f10a-####-82e2e5a701b3 running az1 #.#.#.# vm-20df7a54-####-99806fd20a7b micro true bosh-vsphere-esxi-ubuntu-jammy-go_agent/1.866
Create a runtime config to apply the pre-start-script (or other scripts mentioned above) of the os-conf release to selected deployments/instance groups/jobs.
Refer to the BOSH document for details of runtime config properties.
For example, the following runtime config applies to the master/worker instance group shown previously.
$ cat osconf-runtime.yml
releases:
- name: os-conf
version: 23.0.0
addons:
- name: osconf-prestart-config
jobs:
- name: pre-start-script
release: os-conf
properties:
script: |-
#!/bin/bash
if [ -f /var/vcap/jobs/bosh-dns/config/config.json ]; then
echo "# this is a test " > /var/vcap/jobs/bosh-dns/config/osconf-test.txt
fi
include:
instance_groups:
- master
- worker
Create the runtime config
$ bosh update-runtime-config --name=osconf-prestart-config osconf-runtime.yml
3. Generate the manifest of this testdep deployment and deploy it again to apply the runtime config
$ bosh -d testdep deploy testdep_manifest.yml
Using environment '#.#.#.#' as client 'ops_manager'
Using deployment 'testdep'
releases:
+ - name: os-conf
+ version: 23.0.0
addons:
+ - jobs:
+ - name: pre-start-script
+ properties:
+ script: "<redacted>"
+ release: os-conf
+ name: tkgi-prestart-config
Continue? [yN]: y
......
4. Verify the pre-start-script is executed successfully
$ bosh -d testdep ssh -c 'sudo ls -l /var/vcap/jobs/bosh-dns/config/osconf-test.txt' | grep stdout
worker/7f24f10a-####-82e2e5a701b3: stdout | -rw-r--r-- 1 root root 18 Oct 28 07:13 /var/vcap/jobs/bosh-dns/config/osconf-test.txt
master/d8cf70de-####-43b47c44a019: stdout | -rw-r--r-- 1 root root 18 Oct 28 07:12 /var/vcap/jobs/bosh-dns/config/osconf-test.txt