Skip to content

Instantly share code, notes, and snippets.

@guss77
Created December 6, 2017 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guss77/d12c14594a431e4789fe47d2b2bb97bc to your computer and use it in GitHub Desktop.
Save guss77/d12c14594a431e4789fe47d2b2bb97bc to your computer and use it in GitHub Desktop.
Create a YAML mapping file for CloudFormation to select a CentOS AMI
#!/bin/bash
(
cat <<EOF
Mappings:
CentOSRegionImages:
EOF
curl -s 'https://wiki.centos.org/Cloud/AWS' | xmllint -html --xpath '//table[1]/tbody/tr' - | perl -nle '
m|CentOS Linux (\d+)| and $version=$1;
m|>\s*(\w{2}-\w+-\d)| and $region=$1;
m|>\s*(ami-\w+)| and $amis{$region}->{"centos$version"} = $1;
END {
for my $region (keys %amis) {
print " $region: { ". join(", ", map { "$_: \"".$amis{$region}->{$_}."\"" } (keys %{$amis{$region}})) . " }";
}
}' | sort
) > centos-images.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment