Skip to content

Instantly share code, notes, and snippets.

@skippy
Created December 31, 2014 18:38
Show Gist options
  • Save skippy/d539442ada90be06459c to your computer and use it in GitHub Desktop.
Save skippy/d539442ada90be06459c 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!)
#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); \
az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone); \
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},az=$${az},region=$${region},$${sgs}\'" >> $conf_file; \
systemctl daemon-reload; \
'
@brodkin
Copy link

brodkin commented Feb 11, 2015

I had to create the directory before I could write out the file... https://gist.github.com/brodkin/b4fbcdc172cf8ddd06cf
Once I did that it worked perfectly!

@cbsmith
Copy link

cbsmith commented Dec 2, 2015

I added some tweaks for additional meta info: https://gist.github.com/cbsmith/e94e7525906bbe3b3be6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment