Created
December 31, 2014 18:38
-
-
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!)
This file contains 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); \ | |
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; \ | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!