Packerizing your config
Walks through installing Packer, authenticating with AWS, building an AMI, launching an EC2 instance, and connecting to a WordPress site.
What this file does
Walks through installing Packer, authenticating with AWS, building an AMI, launching an EC2 instance, and connecting to a WordPress site.
When to use it
- You want to automate creation of a WordPress AMI with Packer
- You need a quickstart for Packer with AWS and Ubuntu
- You are following a beginner Linux/WordPress tutorial that uses Packer
Assumes this stack
Packerizing your config
- Install packer here.
- Read up on the docs for your cloud/platform/stack (we're using AWS here).
- You can use what's in this directory to get started!
Set up authentication
You'll need API access to your amazon account. To get this set up, log into your AWS Admin Console and navigate to: - IAM - Users - "Add Users" and pick a username - Select AWS Credential Type: "Access key - Programmatic access" - "Next - Permissions" -- add fine-grained permissions here, "Attach policies directly" and attaching AdministratorAccess will work, but it's not particularly safe or best practice. - After creating the IAM User, copy the "AWS Access Key ID" and "Secret Access key" that's displayed. The secret key will only be shown this once, so store it safely!
Export those keys in the shell where you'll be running packer commands, and you'll be good to go:
export AWS_ACCESS_KEY_ID="<YOUR_AWS_ACCESS_KEY_ID>"
export AWS_SECRET_ACCESS_KEY="<YOUR_AWS_SECRET_ACCESS_KEY>"
Run Packer
packer init .
# Format your packer code, if you've changed my example around
packer fmt .
packer validate .
Now you can build your AMI!
packer build wordpress-aws-ubuntu.pkr.hcl
Write down important output
This is an ugly hack which I made to keep things simple and easy to follow:
- The autogenerated mysql password is echoed out to the shell AND written into /etc/packer-setup.log by default.
Use your instance!
- Go to your AMIs -- they're region specific, so make sure your packer builder region and the one your're looking at in your AWS Console are the same.
- Select the AMI you just built and click "Launch instance from AMI"
- Configure EC2 Instance options like your SSH key and how big the storage volume should be
- Launch the instance and wait for it to boot.
- Grab your instance's public IP (click on the instance, then select the "networking" tab and look for "Public IPv4 address")
- Connect via SSH! (username is ubuntu)
ssh ubuntu@yourInstanceIPAddress
Check out your webite!
Open the WordPress Installer in your Browser http://example.com/wp-admin/setup-config.php
Debugging
If you run into any errors after making modifications to this script, debug them! That's where all the learning really happens, anyway. Here are some resources:
- Packer Debugging -
-debugand-on-error=askare extremely useful.
TODO
- get vars into the config files (they've got tutorialinux hardcoded in them)
- compare and tune php.ini
- mysql server root password and mysql_secure_installation
- occasional failure to find mysql server... ==> packer-wordpress-tutorialinux-aws.amazon-ebs.ubuntu: E: Unable to locate package mysql-server
Basics Course
- see this readme
- decompose hands-on course scripts into scriptable chunks
- base setup script (apt installs)
- discuss MANUAL steps -- why are they manual? Can we automate or defer them?
- noninteractive mysql install?
- add vars to make it more configurable
- config file templating using packer vars
What's inside
8 sections covering install, auth, build, output, launch, website check, debugging, and a TODO list with 3 code blocks
Change this for your project
- Replace
tutorialinuxin TODO with your own project name - Replace
http://example.com/wp-admin/setup-config.phpwith your instance's URL - Replace
wordpress-aws-ubuntu.pkr.hclwith your actual Packer template filename
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Exporting AWS credentials as environment variables before running Packer
- Using
packer init,fmt,validate, andbuildas a standard workflow
Related Documents
How you work
Defines personality, planning, task execution, and communication conventions for a coding agent in the Codex CLI environment.
How you work
Defines personality, planning, task execution, and communication guidelines for a coding agent in Codex CLI.
内置 Agent 提示词
Documents the system prompts, tool permissions, and model assignments for six built-in subagents in Claude Code.
perplexity-ai_20250112
Defines the system prompt for Perplexity AI, instructing the assistant on how to answer queries using search results with strict formatting, citation, and query-type rules.