Helper scripts for modifying cloud-config-novajoin.json
Adding two helper scripts to unpack cloud-config-novajoin.json to a more readable form. After editing cloud-config-novajoin.yaml, it still has to be packed into cloud-config-novajoin.json with tools/cloud-config-pack.py. Related-Bug: 1836529 Change-Id: I3d6a3e5f97608f7f8a0070f40ddeb8a7113c33b3
This commit is contained in:
parent
2c8c868a2c
commit
6506855623
14
files/README
Normal file
14
files/README
Normal file
@ -0,0 +1,14 @@
|
||||
This directory contains configuration files placed in /etc/
|
||||
(see setup.cfg for details)
|
||||
|
||||
IMPORTANT: cloud-config-novajoin.json is manually generated from
|
||||
cloud-config-novajoin.yaml, by using tools/cloud-config-unpack.py and
|
||||
tools/cloud-config-pack.py scripts.
|
||||
|
||||
Before editing cloud-config-novajoin.yaml, run tools/cloud-config-unpack.py.
|
||||
After editing cloud-config-novajoin.yaml, run tools/cloud-config-pack.py.
|
||||
This will place your edits in cloud-config-novajoin.json, which is the only
|
||||
file that is installed in /etc/.
|
||||
|
||||
cloud-config-novajoin.json cannot be automatically generated, because we use a
|
||||
setup.py provided by the global requirements repo, which we cannot modify.
|
81
files/cloud-config-novajoin.yaml
Normal file
81
files/cloud-config-novajoin.yaml
Normal file
@ -0,0 +1,81 @@
|
||||
#cloud-config
|
||||
packages:
|
||||
- python-simplejson
|
||||
- ipa-client
|
||||
- ipa-admintools
|
||||
- openldap-clients
|
||||
- hostname
|
||||
write_files:
|
||||
- content: |
|
||||
#!/bin/sh
|
||||
|
||||
function get_metadata_config_drive {
|
||||
if [ -f /run/cloud-init/status.json ]; then
|
||||
# Get metadata from config drive
|
||||
data=`cat /run/cloud-init/status.json`
|
||||
config_drive=`echo $data | python -c 'import json,re,sys;obj=json.load(sys.stdin);ds=obj.get("v1", {}).get("datasource"); print(re.findall(r"source=(.*)]", ds)[0])'`
|
||||
if [[ -b $config_drive ]]; then
|
||||
temp_dir=`mktemp -d`
|
||||
mount $config_drive $temp_dir
|
||||
if [ -f $temp_dir/openstack/latest/vendor_data2.json ]; then
|
||||
data=`cat $temp_dir/openstack/latest/vendor_data2.json`
|
||||
umount $config_drive
|
||||
rmdir $temp_dir
|
||||
else
|
||||
umount $config_drive
|
||||
rmdir $temp_dir
|
||||
fi
|
||||
else
|
||||
echo "Unable to retrieve metadata from config drive."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "Unable to retrieve metadata from config drive."
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function get_metadata_network {
|
||||
# Get metadata over the network
|
||||
data=$(timeout 300 /bin/bash -c 'data=""; while [ -z "$data" ]; do sleep $[ ( $RANDOM % 10 ) + 1 ]s; data=`curl -s http://169.254.169.254/openstack/2016-10-06/vendor_data2.json 2>/dev/null`; done; echo $data')
|
||||
|
||||
if [[ $? != 0 ]] ; then
|
||||
echo "Unable to retrieve metadata from metadata service."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
if ! get_metadata_config_drive; then
|
||||
if ! get_metadata_network; then
|
||||
echo "FATAL: No metadata available"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Get the instance hostname out of the metadata
|
||||
fqdn=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("join", {}).get("hostname", ""))'`
|
||||
|
||||
if [ -z "$fqdn" ]; then
|
||||
echo "Unable to determine hostname"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
realm=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("join", {}).get("krb_realm", ""))'`
|
||||
otp=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("join", {}).get("ipaotp", ""))'`
|
||||
|
||||
hostname=`/bin/hostname -f`
|
||||
|
||||
# run ipa-client-install
|
||||
OPTS="-U -w $otp --hostname $fqdn --mkhomedir"
|
||||
if [ -n "$realm" ]; then
|
||||
OPTS="$OPTS --realm=$realm"
|
||||
fi
|
||||
ipa-client-install $OPTS
|
||||
path: /root/setup-ipa-client.sh
|
||||
permissions: '0700'
|
||||
owner: root:root
|
||||
runcmd:
|
||||
- sh -x /root/setup-ipa-client.sh > /var/log/setup-ipa-client.log 2>&1
|
9
tools/cloud-config-pack.py
Executable file
9
tools/cloud-config-pack.py
Executable file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import json
|
||||
|
||||
with open('files/cloud-config-novajoin.yaml') as config_unpacked:
|
||||
config = config_unpacked.read()
|
||||
with open('files/cloud-config-novajoin.json', 'w') as cloud_config:
|
||||
json.dump({'cloud-init': config}, cloud_config)
|
||||
cloud_config.write('\n')
|
8
tools/cloud-config-unpack.py
Executable file
8
tools/cloud-config-unpack.py
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import json
|
||||
|
||||
with open('files/cloud-config-novajoin.json') as cloud_config:
|
||||
config = json.load(cloud_config)['cloud-init']
|
||||
with open('files/cloud-config-novajoin.yaml', 'w') as config_unpacked:
|
||||
config_unpacked.write(config)
|
Loading…
x
Reference in New Issue
Block a user