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-idempotent.yaml
76 lines (63 loc) · 1.99 KB
/
vagrant-test-idempotent.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
---
#
# This section fires up a set of instances 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_name: lucid32
box_path: http://files.vagrantup.com/lucid32.box
vm_name: frank
tasks:
- name: Fire up a set of vagrant instances to log into
local_action: vagrant
state=present
box_name='{{box_name}}'
box_path='{{box_path}}'
vm_name='{{vm_name}}'
count=3
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 host's contact info into the inventory (the hostname is a unique ID from Vagrant ... )
action: add_host
hostname='{{item.vagrant_name}}'
ansible_ssh_port='{{item.port}}'
ansible_ssh_host='{{item.public_ip}}'
groupname=vagrant_hosts
with_items: '{{vagrant.instances}}'
#
# Run on the vagrant_hosts group, checking that we have basic ssh access...
#
- hosts:
- vagrant_hosts
user: vagrant
vars:
vm_name: frank
gather_facts: True
tasks:
- name: Let's see if we can login
action: command uname -a
- name: Let's 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
#
# Shut them down
#
- name: Now shut them down ...
local_action: vagrant
state=absent
vm_name='{{vm_name}}'
- name: Now clear it out ...
local_action: vagrant command=clear