{"id":18947628,"url":"https://github.com/yousafkhamza/packer-ami","last_synced_at":"2026-03-27T03:30:24.935Z","repository":{"id":195965560,"uuid":"376459147","full_name":"yousafkhamza/packer-ami","owner":"yousafkhamza","description":"Packer is a tool for build a golden image also packer is lightweight. As of here, I have used to provision the image using an ansible script, and you guys use these additional options like a shell.","archived":false,"fork":false,"pushed_at":"2021-07-11T09:15:12.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-01T01:19:53.832Z","etag":null,"topics":["ami","aws","cloud","hashicorp","packer"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yousafkhamza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-06-13T06:25:56.000Z","updated_at":"2022-04-18T19:34:28.000Z","dependencies_parsed_at":"2023-09-20T20:13:41.109Z","dependency_job_id":null,"html_url":"https://github.com/yousafkhamza/packer-ami","commit_stats":null,"previous_names":["yousafkhamza/packer-ami"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2Fpacker-ami","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2Fpacker-ami/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2Fpacker-ami/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2Fpacker-ami/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yousafkhamza","download_url":"https://codeload.github.com/yousafkhamza/packer-ami/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239946876,"owners_count":19723014,"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":["ami","aws","cloud","hashicorp","packer"],"created_at":"2024-11-08T13:10:42.382Z","updated_at":"2025-02-21T02:43:46.842Z","avatar_url":"https://github.com/yousafkhamza.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Packer Golden Image Builder (AWS)\n[![Builds](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger)\n\n---\n\n## Description\nPacker is a tool for build a golden images also packer is lightwight. As of here, I have used to provision the image using a ansible script and who you guys use this additional options like shell. \n\n----\n## Feature\n\n- Easy to build a image with a lightweight code \n- You can integrate this with automation jenkins (Architacutre included with jenkins)\n\n-----\n\n### Pre-Requests\n- Need a IAM user with ec2 access \n\n-----\n### How to install packer on your machine\nReference: [packer download](https://www.packer.io/downloads)\n```sh\nwget https://releases.hashicorp.com/packer/1.7.3/packer_1.7.3_linux_amd64.zip\nunzip packer_1.7.3_linux_amd64.zip\nmv packer /usr/bin/\n```\nCheck packer version using\n```sh\npacker version\n```\n----\n\n### How to use\n\n```sh\nyum install git -y\namazon-linux-extras install ansible2  \u003c------- (optional when you use)\ngit clone https://github.com/yousafkhamza/packer-ami.git\ncd packer-ami\npacker build main.pkr.hcl\n```\n\n-----\n## Architecture\n\n\n![alt text](https://i.ibb.co/HVMkmhG/packer.jpg)\n\n-----\n### Behind the file\n\nvim main.pkr.hcl\n```sh\n# ---------------------------------------------\n# Variable declaration\n# ---------------------------------------------\nvariable \"access_key\" {\n  default = \"\u003cyour access key\u003e\"\n}\n\nvariable \"secret_key\" {\n  default = \"\u003cyour secret key\u003e\"\n}\n\nvariable \"type\" {\n  default = \"t2.micro\"\n}\n\nvariable \"region\" {\n    default = \"us-east-1\"\n}\n\n# -----------------------------------------------\n# Timestamp variable declaration on running time\n# -----------------------------------------------\nlocals { timestamp = regex_replace(timestamp(), \"[- TZ:]\", \"\") }\n\n#--------------------------------------------------\n# Image Creation \n#--------------------------------------------------\n\nsource \"amazon-ebs\" \"webserver\" {\n   source_ami_filter {\n    filters = {\n       virtualization-type = \"hvm\"\n       name = \"amzn2-ami-hvm-2.0.*.1-x86_64-ebs\"\n       root-device-type = \"ebs\"\n    }\n    owners = [\"amazon\"]\n    most_recent = true\n  }\n  access_key         = \"${var.access_key}\"\n  ami_name           = \"packer-ami ${local.timestamp}\"\n  instance_type      = \"${var.type}\"\n  region             = \"${var.region}\"\n  secret_key         = \"${var.secret_key}\"\n  security_group_ids = [ \"sg-0c8c8b94dc5c55c1d\" ]\n  ssh_username       = \"ec2-user\"\n}\n\nbuild {\n  sources = [\"source.amazon-ebs.webserver\"]\n  \n    provisioner \"ansible\" {\n      playbook_file = \"./play.yml\"\n  }\n\n  post-processor \"shell-local\" {\n    inline = [\"echo AMI Created\"]\n  }\n}\n```\n----\nvim play.yml (Image provision using ansible)\n```sh\n---\n- name: 'Provision Image'\n  hosts: localhost\n  gather_facts: false\n  become: true\n  vars:\n    - git_url: \"https://github.com/yousafkhamza/aws-elb-site.git\"\n  tasks:\n    - name: \"install Apache\"\n      yum:\n        name:\n          - httpd\n        state: present\n\n    - name: \"Service start\"\n      service:\n        name: httpd\n        state: restarted\n        enabled: true\n\n    - name: \"Cloning Git Repository\"\n      git:\n        repo: \"{{ git_url }}\"\n        dest: /var/website/\n\n    - name: \"Copy from /var/website to /var/www/html/\"\n      copy:\n        src: /var/website/\n        dest: /var/www/html/\n        owner: apache\n        group: apache\n        remote_src: true\n```\n\n----\n## Conclusion\nIt's just build a golden image through a new tool using packer and its tool designed from hashicorp and furthermore it's lightweight machine image builder.\n\n### ⚙️ Connect with Me\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"mailto:yousaf.k.hamza@gmail.com\"\u003e\u003cimg src=\"https://img.shields.io/badge/Gmail-D14836?style=for-the-badge\u0026logo=gmail\u0026logoColor=white\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://www.linkedin.com/in/yousafkhamza\"\u003e\u003cimg src=\"https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white\"/\u003e\u003c/a\u003e \n\u003ca href=\"https://www.instagram.com/yousafkhamza\"\u003e\u003cimg src=\"https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge\u0026logo=instagram\u0026logoColor=white\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://wa.me/%2B917736720639?text=This%20message%20from%20GitHub.\"\u003e\u003cimg src=\"https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge\u0026logo=whatsapp\u0026logoColor=white\"/\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyousafkhamza%2Fpacker-ami","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyousafkhamza%2Fpacker-ami","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyousafkhamza%2Fpacker-ami/lists"}