-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuclalib_packer.yml
107 lines (87 loc) · 2.9 KB
/
uclalib_packer.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
- name: Playbook uclalib_role_packer.yml
hosts: '{{ hosts | default ("localhost") }}'
gather_facts: false
connection: local
tasks:
- name: 'Assert vm_name is set'
assert:
that: vm_name is defined
- name: Add host
add_host:
name: '{{ vm_name }}'
# ---
- name: 'Playbook uclalib_role_packer.yml pt 2'
hosts: '{{ vm_name }}'
gather_facts: false
pre_tasks:
- name: Gathering Facts (minus /etc/facts.d)
setup:
fact_path: /nonexistent
gather_subset: '!all'
connection: local
- name: Convert name to short
set_fact:
vm_short_name: '{{ vm_name | regex_replace("^([^.]+)\.?.*", "\1") }}'
when: false
- name: Set FQDN
set_fact:
vm_fqdn: '{{ (vm_name is regex("\.")) | ternary (
vm_name,
vm_name ~ "." ~ ansible_domain
) }}'
- name: 'Look up IP address'
set_fact:
vm_ip_dig: '{{ hostvars[inventory_hostname].ansible_host | default(lookup("dig", vm_fqdn)) }}'
- name: 'Set IP address, if resolvable'
set_fact:
vm_ip: '{{ vm_ip_dig }}'
when:
- vm_ip_dig != "NXDOMAIN"
- vm_ip == 'dhcp'
- name: 'Fall back to dhcp'
set_fact:
vm_ip: 'dhcp'
when: vm_ip is not defined or vm_ip == ''
- name: Set the nameservers
set_fact:
nameservers: '{{ ansible_dns.nameservers }}'
when: nameservers is not defined
- name: 'Set bootstring when IP address is known'
set_fact:
vm_boot_string: >
ip={{ vm_ip }}::{{ ( vm_ip + "/" + subnet_size )
| ipaddr( "1" ) | regex_replace( "/", ":" ) }}:{{ vm_fqdn }}
{%- for nameserver in nameservers %} nameserver={{ nameserver }}
{%- endfor %}
when: ( vm_ip | default( "dhcp" ) ) != "dhcp"
- name: 'Set bootstring hostname when using dhcp'
set_fact:
vm_boot_string: 'ip=::::{{ vm_fqdn }}::dhcp:'
when: ( vm_ip | default( "dhcp" ) ) == "dhcp"
- name: Set network
set_fact:
vsphere_network: '{{ vlan_map[ vm_ip | regex_replace ("\.([^.]+)$", "") ] }}'
when: vsphere_network == ''
# this playbook is pulling in values from the role defaults/main.yml !
- name: Set VM folder
set_fact:
vsphere_folder: '{{ vm_folder_map[ inventory_hostname[0] ] }}'
when:
- vsphere_folder == ''
- vm_folder_map[ inventory_hostname[0] ] is defined
- not convert_to_template|bool
- name: Set Template folder
set_fact:
vsphere_folder: '{{ template_folder }}'
when:
- vsphere_folder == ''
- convert_to_template|bool
- name: Set Provisioning Script
set_fact:
playbook_file: '{{ (convert_to_template | bool) | ternary (provisioner.template, provisioner.vm) }}'
when:
- playbook_file is not defined
roles:
- name: uclalib_role_packer
connection: local