-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_vrf.yml
57 lines (51 loc) · 2.15 KB
/
create_vrf.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
# ======= How to run standalone:
# boburciu@WX-5CG020BDT2: ~$ cd ~/netbox-ansible-automation
# boburciu@WX-5CG020BDT2:~/netbox-ansible-automation$ ansible-playbook -i ./hosts -v create_vrf.yml -e 'tenant_name="TestTen"'
- name: Create VRF
connection: local
hosts: docker_netbox_19216820023
gather_facts: False
collections:
- netbox.netbox
tasks:
# - include_vars: external_vars.yml # where "url_var: http://192.168.200.23:8001/"
# creating a VRF assumes knowledge of tenant id;
# query first a list of tenants and get id of only one of interest
# - name: Obtain id of specific tenant "Test_tenant" from Netbox
# debug:
# msg: "{{ item.value.id }}"
# register: tenant_id
# loop: "{{ query('netbox.netbox.nb_lookup', 'tenants', api_filter='name=TestTen',
# api_endpoint=url_var,
# token=token_var) }}"
# - name: See tenant id
# debug:
# msg: "{{tenant_id.results[0].item.value.id}}"
# msg: "{{tenant_id.results[0].item.key | int }}"
- name: Create VRF with all information
netbox.netbox.netbox_vrf:
netbox_url: '{{ url_var }}'
netbox_token: "{{ token_var }}"
data:
name: "{{ vrf_name }}"
rd: "{{ vrf_rd }}"
tenant: "{{ tenant_name }}"
# tenant: "{{tenant_id.results[0].item.value.id | int }}"
# tenant: "{{ tenant_name | int }}"
description: "{{ vrf_description }}"
enforce_unique: true # prevent duplicate prefixes/IP addresses within this VRF, true or false
state: present # prevent duplicate prefixes/IP addresses within this VRF, true or false
ignore_errors: True
- name: Assign tag to VRF, when available
netbox.netbox.netbox_vrf:
netbox_url: '{{ url_var }}'
netbox_token: "{{ token_var }}"
data:
name: "{{ vrf_name }}"
rd: "{{ vrf_rd }}"
tenant: "{{ tenant_name }}"
tags:
- "{{ vrf_tag }}"
state: present
ignore_errors: True
when: vrf_tag is defined