Add an Amazon template for building AMIs 09/10509/2
authorTrevor Bramwell <tbramwell@linuxfoundation.org>
Tue, 8 May 2018 01:56:56 +0000 (18:56 -0700)
committerTrevor Bramwell <tbramwell@linuxfoundation.org>
Thu, 10 May 2018 18:45:29 +0000 (11:45 -0700)
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 <ssh_user>@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 <tbramwell@linuxfoundation.org>
templates/builder-aws.json [new file with mode: 0644]
vars/cloud-env-aws.json.example [new file with mode: 0644]

diff --git a/templates/builder-aws.json b/templates/builder-aws.json
new file mode 100644 (file)
index 0000000..f9b5b12
--- /dev/null
@@ -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 (file)
index 0000000..c50792a
--- /dev/null
@@ -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": ""
+}