-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
91 lines (79 loc) · 2.62 KB
/
playbook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
- name: Packer Demo Installs
hosts: packerdemo
become: true
tasks:
# Stat the path tot he aws cloud instance folder, so we can differentiate
# between running the playbook on AWS and on a VirtualBox-ISO setup.
- name: Stat the AWS Path
stat:
path: /var/lib/cloud/instance
register: aws_machine
- name: Wait for us to be completely done booting when we're in AWS
wait_for: path=/var/lib/cloud/instance/boot-finished
when: aws_machine.stat.exists == True
- name: Update APT
apt:
update_cache: true
cache_valid_time: 3600
become: true
- name: Install Guest Additions Dependencies for VirtualBox Guest Additions
apt:
pkg: "{{ item }}"
with_items:
- build-essential
- dkms
- nfs-common
when: aws_machine.stat.exists == False
# Note, that Packer witll *automatically* copy this from our locally
# installed VirtualBox.
- name: Mount VirtualBox guest additions ISO.
mount:
name: /tmp/vbox
src: "/home/vagrant/VBoxGuestAdditions.iso"
opts: loop
state: mounted
fstype: iso9660
when: aws_machine.stat.exists == False
- name: Run VirtualBox guest additions installation.
shell: sh /tmp/vbox/VBoxLinuxAdditions.run
failed_when: false
when: aws_machine.stat.exists == False
- name: Unmount VirtualBox guest additions ISO.
mount:
name: /tmp/vbox
src: "/home/vagrant/VBoxGuestAdditions.iso"
state: absent
fstype: iso9660
when: aws_machine.stat.exists == False
- name: Delete VirtualBox guest additions ISO.
file:
path: "/home/vagrant/VBoxGuestAdditions.iso"
state: absent
when: aws_machine.stat.exists == False
- name: Modify sudoers file so vagrant doesn't need a password.
lineinfile:
dest: /etc/sudoers
state: present
regexp: "^{{ item.key }}"
line: '{{ item.line }}'
validate: 'visudo -cf %s'
with_items:
- { key: 'vagrant', line: 'vagrant ALL=(ALL) NOPASSWD:ALL' }
when: aws_machine.stat.exists == False
- name: Create .ssh directory for Vagrant user
file:
state: directory
path: /home/vagrant/.ssh
owner: vagrant
group: vagrant
mode: 0700
when: aws_machine.stat.exists == False
- name: Set Access Key for Vagrant when a *local* box.
copy:
src: ./files/vagrant.pub
dest: /home/vagrant/.ssh/authorized_keys
owner: vagrant
group: vagrant
mode: 0600
when: aws_machine.stat.exists == False