-
-
Save cbsmith/e94e7525906bbe3b3be6 to your computer and use it in GitHub Desktop.
modifying fleet metadata (from aws meta-data service) before fleet.service start; this is a proof of concept (but it works!)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cloud-config | |
--- | |
coreos: | |
units: | |
- name: update-fleet-metadata.service | |
command: start | |
content: |- | |
[Unit] | |
Description=Update Fleet metadata tag | |
Before=fleet.service | |
Requires=fleet.service | |
[Service] | |
Type=oneshot | |
RemainAfterExit=no | |
EnvironmentFile=/etc/environment | |
ExecStart=/bin/bash -c '\ | |
conf_file=/run/systemd/system/fleet.service.d/21-metadata.conf; \ | |
instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id); \ | |
instance_type=$(curl -s http://169.254.169.254/latest/meta-data/instance-type); \ | |
az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone); \ | |
memory=$(free -m -t | tail -1 | awk \'{print $2}\'); | |
processors=$(egrep -c \'^processor[[:space:]]+:\' /proc/cpuinfo); \ | |
region=$${az::-1}; \ | |
sgs=$(curl -s http://169.254.169.254/latest/meta-data/security-groups/ | sed "s/^/sg_/" | sed "s/$/=1/" | tr "\\n", ","); \ | |
echo "[Service]" > $conf_file; \ | |
echo "Environment=\'FLEET_METADATA=instance_id=$${instance_id},instance-type=$${instance_type},az=$${az},memory=$${memory},processors=$${processors},region=$${region},$${sgs}\'" >> $conf_file; \ | |
systemctl daemon-reload; \ | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment