From: Trevor Bramwell Date: Tue, 8 May 2018 01:56:56 +0000 (-0700) Subject: Add an Amazon template for building AMIs X-Git-Tag: v0.1.0~33 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F09%2F10509%2F2;p=releng%2Fcommon-packer.git Add an Amazon template for building AMIs The differences between this builder and the openstack one are the cloud specific options passed, and the disabling of ANSIBLE_PIPELINING. For some reason ansible is not able to set up the local ssh connection (ssh @127.0.0.1) on the EC2 instance after transfering the playbook files, yet it can successfully ssh to the machine. Disabling the pipelining support opens a new ssh connection each time ansible runs a task. This takes more time, but works. This patch also includes an amazon cloud example var file. Change-Id: I2b9f273e86fd7bc1ddfde34d26eebfd6249a6a0a Signed-off-by: Trevor Bramwell --- diff --git a/templates/builder-aws.json b/templates/builder-aws.json new file mode 100644 index 0000000..f9b5b12 --- /dev/null +++ b/templates/builder-aws.json @@ -0,0 +1,71 @@ +{ + "description": "Build an AMI for use as a CI builder", + "variables": { + "ansible_roles_path": ".galaxy", + "aws_access_key": null, + "aws_secret_key": null, + "security_group_id": null, + "source_ami_filter_name": null, + "source_ami_filter_owner": null, + "aws_instance_type": "t2.micro", + "aws_region": "us-west-2", + "vpc_id": null, + "subnet_id": null, + "ssh_user": null, + "distro": null, + "cloud_user_data": null, + "ssh_proxy_host": "" + }, + "builders": [ + { + "name": "aws", + "access_key": "{{user `aws_access_key`}}", + "ami_name": "ZZCI - {{user `distro`}} - builder-aws - {{isotime \"20060102-1504\"}}", + "instance_type": "{{user `aws_instance_type`}}", + "region": "{{user `aws_region`}}", + "secret_key": "{{user `aws_secret_key`}}", + "security_group_id": "{{user `security_group_id`}}", + "source_ami_filter": { + "filters": { + "name": "{{user `source_ami_filter_name`}}", + "root-device-type": "ebs", + "virtualization-type": "hvm" + }, + "most_recent": true, + "owners": ["{{user `source_ami_filter_owner`}}"] + }, + "ssh_username": "{{user `ssh_user`}}", + "ssh_proxy_host": "{{user `ssh_proxy_host`}}", + "vpc_id": "{{user `vpc_id`}}", + "subnet_id": "{{user `subnet_id`}}", + "type": "amazon-ebs", + "user_data_file": "{{user `cloud_user_data`}}" + } + ], + "provisioners": [ + { + "type": "shell", + "scripts": [ + "common-packer/provision/install-python.sh" + ], + "execute_command": "chmod +x {{ .Path }}; if [ \"$UID\" == \"0\" ]; then {{ .Vars }} '{{ .Path }}'; else {{ .Vars }} sudo -E '{{ .Path }}'; fi" + }, + { + "type": "shell-local", + "command": "./common-packer/ansible-galaxy.sh {{user `ansible_roles_path`}}" + }, + { + "type": "ansible", + "user": "{{user `ssh_user`}}", + "playbook_file": "provision/local-builder.yaml", + "ansible_env_vars": [ + "ANSIBLE_NOCOWS=1", + "ANSIBLE_PIPELINING=False", + "ANSIBLE_HOST_KEY_CHECKING=False", + "ANSIBLE_ROLES_PATH={{user `ansible_roles_path`}}", + "ANSIBLE_CALLBACK_WHITELIST=profile_tasks", + "ANSIBLE_STDOUT_CALLBACK=debug" + ] + } + ] +} diff --git a/vars/cloud-env-aws.json.example b/vars/cloud-env-aws.json.example new file mode 100644 index 0000000..c50792a --- /dev/null +++ b/vars/cloud-env-aws.json.example @@ -0,0 +1,8 @@ +{ + "aws_access_key": "ACCESSKEY", + "aws_secret_key": "SECRETKEY", + "subnet_id": "subnet-null", + "security_group_id": "sg-null", + "vpc_id": "vpc-null", + "ssh_proxy_host": "" +}