Skip to content

Instantly share code, notes, and snippets.

@sirhopcount
Forked from cbsmith/cloud-config.yml
Created September 26, 2016 06:25
Show Gist options
  • Save sirhopcount/9064522fac1640de06cf77312fe1e127 to your computer and use it in GitHub Desktop.
Save sirhopcount/9064522fac1640de06cf77312fe1e127 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); \
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