This repository has been archived by the owner on Jun 22, 2021. It is now read-only.
forked from caljess599/ansible-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvagrant-test.yaml
84 lines (69 loc) · 2.25 KB
/
vagrant-test.yaml
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
---
#
# This section fires up a set of guests dynamically using vagrant,
# registers it in the inventory under
# the group "vagrant_hosts"
# then logs in and pokes around.
#
- hosts:
- localhost
connection: local
gather_facts: False
vars:
box_name2: lucid32
box_path2: http://files.vagrantup.com/lucid32.box
vm_name2: frank
tasks:
- name: Fire up a set of vagrant instances to log into
local_action: vagrant
args:
command: up
box_name: "{{box_name2}}"
box_path: "{{box_path2}}"
vm_name: "{{vm_name2}}"
count: 2
config_code: |
config.vm.provider "virtualbox" do |vb|
vb.memory = 256
end
log: true
register: vagrant
- name: Remind us about the vagrant private key ...
action: debug
msg="Be sure to add the ssh private key for vagrant, here ... '{{vagrant.instances[0].key}}'."
- name: Host info ...
action: debug
msg='{{item.public_ip}}:{{item.port}}'
with_items: '{{vagrant.instances}}'
- name: Capture that hosts contact info into the inventory (the hostname is a unique ID from Vagrant ... )
action: add_host
groupname=vagrant_hosts
hostname='{{item.vagrant_name}}'
ansible_ssh_port='{{item.port}}'
ansible_ssh_host='{{item.public_ip}}'
ansible_ssh_private_key_file='{{item.key}}'
with_items: '{{vagrant.instances}}'
#
# Run on the vagrant_hosts group, checking that we have basic ssh access...
#
- hosts:
- vagrant_hosts
user: vagrant
vars:
vm_name2: frank
gather_facts: True
tasks:
- name: Lets see if we can login
action: command uname -a
- name: Lets see all the ansible vars about vagrant hosts...
action: setup
- name: Generate a ./blah_ansible.vars to check for hostvars
action: template src=test-vagrant-hostinfo.j2 dest=/tmp/localhost_ansible.vars
- name: Take a look at the outputs ... (Messy!)
action: command cat /tmp/localhost_ansible.vars
- name: Shut them down ...
local_action: vagrant
state=halt
vm_name='{{vm_name2}}'
- name: Now clear it out ...
local_action: vagrant command=clear