{"id":16655019,"url":"https://github.com/ycliuhw/userdata-generator","last_synced_at":"2025-03-12T18:40:38.040Z","repository":{"id":62586728,"uuid":"122299369","full_name":"ycliuhw/userdata-generator","owner":"ycliuhw","description":"troposphere user data generator for human","archived":false,"fork":false,"pushed_at":"2018-02-24T04:51:14.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-19T16:43:06.839Z","etag":null,"topics":["cloudformation","python3","troposphere","userdata"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/userdata-cool","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ycliuhw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-21T06:12:11.000Z","updated_at":"2018-02-24T04:51:53.000Z","dependencies_parsed_at":"2022-11-03T22:09:53.485Z","dependency_job_id":null,"html_url":"https://github.com/ycliuhw/userdata-generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ycliuhw%2Fuserdata-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ycliuhw%2Fuserdata-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ycliuhw%2Fuserdata-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ycliuhw%2Fuserdata-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ycliuhw","download_url":"https://codeload.github.com/ycliuhw/userdata-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243275241,"owners_count":20265144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudformation","python3","troposphere","userdata"],"created_at":"2024-10-12T09:51:45.023Z","updated_at":"2025-03-12T18:40:38.008Z","avatar_url":"https://github.com/ycliuhw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# userdata-generator\n\n![build-status](http://nginx.k8s.domainsecurity.cc/api/badges/ycliuhw/userdata-generator/status.svg?branch=master) [![codecov](https://codecov.io/gh/ycliuhw/userdata-generator/branch/master/graph/badge.svg)](https://codecov.io/gh/ycliuhw/userdata-generator)\n[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)\n[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/)\n[![PyPI](https://img.shields.io/badge/pypi-v0.1.2-brightgreen.svg)](https://pypi.python.org/pypi/userdata-cool)\n\ntroposphere user data generator for `human`\n\n---\n\n## Installation\n\n---\n\n### from pypi\n\n---\n\n```bash\npip install userdata-cool\n```\n\n### from source\n\n---\n\n```bash\ngit clone https://github.com/ycliuhw/userdata-generator.git\ncd userdata-generator\n\nvirtualenv -p $(which python3.6) venv\nsource venv/bin/activate\npython setup.py install\n```\n\n## current support elements\n\n* Ref(Resource)\n* GetAtt(Resource, AttributeName)\n\n## simply write user data like this -\u003e\n\n```bash\n#!/bin/bash\nsudo apt update \u0026\u0026 apt install -y python-setuptools python-pip jq awscli\nsudo pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n\ncurl -s https://packagecloud.io/install/repositories/EventStore/EventStore-OSS/script.deb.sh | sudo bash\nsudo apt update \u0026\u0026 apt install -y eventstore-oss=4.0.3\n\nexport AWS_DEFAULT_REGION=`/usr/bin/curl -sf http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region`\n\nInstanceID=`/usr/bin/curl -sf http://169.254.169.254/latest/meta-data/instance-id/`\nASG_NAME=`/usr/bin/aws ec2 describe-instances --instance-ids ${InstanceID} --query \"Reservations[0].Instances[0].Tags[?Key=='aws:autoscaling:groupName'].Value\" | jq  -r '.|first'`\n\n# get current private ip list\nPrivateIPs=$( \\\n    /usr/bin/aws ec2 describe-instances \\\n    --instance-ids \\\n    $( \\\n        /usr/bin/aws autoscaling describe-auto-scaling-instances \\\n            --output text \\\n            --query \"AutoScalingInstances[?contains(AutoScalingGroupName, 'Ref(AWS::StackName)')].InstanceId\" \\\n    ) \\\n    --query \"Reservations[].Instances[].PrivateIpAddress\" | jq 'map({\"Value\": .})' \\\n    )\n\nZONE_ID=`/usr/bin/aws route53 list-hosted-zones | jq -r '.HostedZones[]|select(.Name==\"example.com.au.\")|.Id'|cut -d'/' -f3`\n\n# update router53 records\n/usr/bin/aws route53 change-resource-record-sets --hosted-zone-id ${ZONE_ID} --change-batch \"{\n\\\\\"Changes\\\\\": [{\\\\\"Action\\\\\": \\\\\"UPSERT\\\\\",\\\\\"ResourceRecordSet\\\\\": {\\\\\"Name\\\\\": \\\\\"Ref(es-dns-lookup.example.com.au)\\\\\",\\\\\"Type\\\\\": \\\\\"A\\\\\",\\\\\"TTL\\\\\": 60,\\\\\"ResourceRecords\\\\\": ${PrivateIPs}}}\n]\n}\"\n\nEIP_Allocate_ID=`/usr/bin/aws ec2 describe-tags --filter Name=resource-id,Values=${InstanceID} | jq -r '.Tags[] | select(.Key==\"{{elastic_ip_tag_name}}\") | .Value'`\n/usr/bin/aws ec2 associate-address --instance-id ${InstanceID} --allocation-id ${EIP_Allocate_ID}\n\necho $(GetAtt(myElb, DNSName))\n\n# wait s for network stable\n/bin/sleep 60\ncfn-init -s Ref(AWS::StackName) -r awesome-stack-name --region=Ref(AWS::Region) -c doIt\n```\n\nthen this small tool will convert it to `troposphere` - `Join` or `Base64` for machine, `rendered.to_dict()` will be like -\u003e\n\n```python\n{\n    \"Fn::Base64\": {\n        \"Fn::Join\": [\n            \"\",\n            [\n                \"#!/bin/bash\\nsudo apt update \u0026\u0026 apt install -y python-setuptools python-pip jq awscli\\nsudo pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\\n\\ncurl -s https://packagecloud.io/install/repositories/EventStore/EventStore-OSS/script.deb.sh | sudo bash\\nsudo apt update \u0026\u0026 apt install -y eventstore-oss=4.0.3\\n\\nexport AWS_DEFAULT_REGION=`/usr/bin/curl -sf http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region`\\n\\nInstanceID=`/usr/bin/curl -sf http://169.254.169.254/latest/meta-data/instance-id/`\\nASG_NAME=`/usr/bin/aws ec2 describe-instances --instance-ids ${InstanceID} --query \\\"Reservations[0].Instances[0].Tags[?Key=='aws:autoscaling:groupName'].Value\\\" | jq  -r '.|first'`\\n\\n# get current private ip list\\nPrivateIPs=$(     /usr/bin/aws ec2 describe-instances     --instance-ids     $(         /usr/bin/aws autoscaling describe-auto-scaling-instances             --output text             --query \\\"AutoScalingInstances[?contains(AutoScalingGroupName, '\",\n                {\n                    \"Ref\": \"AWS::StackName\"\n                },\n                \"')].InstanceId\\\"     )     --query \\\"Reservations[].Instances[].PrivateIpAddress\\\" | jq 'map({\\\"Value\\\": .})'     )\\n\\nZONE_ID=`/usr/bin/aws route53 list-hosted-zones | jq -r '.HostedZones[]|select(.Name==\\\"example.com.au.\\\")|.Id'|cut -d'/' -f3`\\n\\n# update router53 records\\n/usr/bin/aws route53 change-resource-record-sets --hosted-zone-id ${ZONE_ID} --change-batch \\\"{\\n\\\\\\\"Changes\\\\\\\": [{\\\\\\\"Action\\\\\\\": \\\\\\\"UPSERT\\\\\\\",\\\\\\\"ResourceRecordSet\\\\\\\": {\\\\\\\"Name\\\\\\\": \\\\\\\"Ref(es-dns-lookup.example.com.au)\\\\\\\",\\\\\\\"Type\\\\\\\": \\\\\\\"A\\\\\\\",\\\\\\\"TTL\\\\\\\": 60,\\\\\\\"ResourceRecords\\\\\\\": ${PrivateIPs}}}\\n]\\n}\\\"\\n\\nEIP_Allocate_ID=`/usr/bin/aws ec2 describe-tags --filter Name=resource-id,Values=${InstanceID} | jq -r '.Tags[] | select(.Key==\\\"{{elastic_ip_tag_name}}\\\") | .Value'`\\n/usr/bin/aws ec2 associate-address --instance-id ${InstanceID} --allocation-id ${EIP_Allocate_ID}\\n\\necho $(\",\n                {\n                    \"Fn::GetAtt\": [\n                        \"myElb\",\n                        \"DNSName\"\n                    ]\n                },\n                \")\\n\\n# wait s for network stable\\n/bin/sleep 60\\ncfn-init -s \",\n                {\n                    \"Ref\": \"AWS::StackName\"\n                },\n                \" -r awesome-stack-name --region=\",\n                {\n                    \"Ref\": \"AWS::Region\"\n                },\n                \" -c doIt\"\n            ]\n        ]\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fycliuhw%2Fuserdata-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fycliuhw%2Fuserdata-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fycliuhw%2Fuserdata-generator/lists"}