· 9 years ago · Aug 24, 2016, 06:32 PM
1
2{
3 "variables": {
4 "aws_access_key": "",
5 "aws_secret_key": ""
6 },
7 "builders": [{
8 "name": "simba",
9 "type": "amazon-ebs",
10 "access_key": "{{user `aws_access_key`}}",
11 "secret_key": "{{user `aws_secret_key`}}",
12 "region": "eu-west-1",
13 "source_ami": "ami-ed82e39e",
14 "instance_type": "t2.micro",
15 "ssh_username": "ubuntu",
16 "ami_name": "sandbox simba packer-simba {{isotime | clean_ami_name}}",
17 "ami_description": "sandbox simba generated by packer",
18 "tags": {"BuildEpoch": "{{ timestamp }}", "env_app": "sandbox_simba"}
19 }],
20 "provisioners": [
21 {
22 "type": "ansible",
23 "user": "ubuntu",
24 "extra_arguments": [ "-vvv" ],
25 "playbook_file": "../../playbooks/test_simba.yml",
26 "host_alias": "simba",
27 "sftp_command": "/usr/lib/openssh/sftp-server -e"
28 }
29 ]
30}
31
32Ansible playbook test_simba.yml
33
34---
35- name: "Testing identities"
36 hosts: all
37 remote_user: ubuntu
38 gather_facts: no
39 tasks:
40 - name: "I should be ubuntu"
41 command: /usr/bin/whoami
42
43 - name: "I should be root"
44 become: yes
45 command: /usr/bin/whoami
46
47 - name: Add a user
48 become: yes
49 user: name=simba shell=/bin/bash
50
51 - name: Install ssh keys to simba
52 remote_user: simba
53 authorized_key:
54 user: simba
55 key: "{{ lookup('file', '../ssh_keys/all_keys') }}"
56 exclusive: yes
57 tags: keys
58
59 - name: "I should be simba"
60 remote_user: simba
61 command: /usr/bin/whoami