Skip to content

Instantly share code, notes, and snippets.

@sky-joker
Created July 10, 2020 16:05
Show Gist options
  • Save sky-joker/3bd82f01dfa999c70bb31df1254d8dac to your computer and use it in GitHub Desktop.
Save sky-joker/3bd82f01dfa999c70bb31df1254d8dac to your computer and use it in GitHub Desktop.
Netboxのprefixesから利用可能なIP一覧を取得するサンプルPlaybook
---
- name: "example playbook"
hosts: localhost
gather_facts: no
vars:
netbox_url: http:/netbox ip or fqdn/api/ipam/prefixes/
netbox_token: change me
target_prefix: "100.64.0.0/24"
module_defaults:
uri:
headers:
Authorization: "Token {{ netbox_token }}"
Accept: "application/json"
tasks:
- name: "Gather prefixes info from NetBox"
uri:
url: "{{ netbox_url }}"
method: GET
register: gather_prefixes_result
- name: "Set prefix_id variable"
set_fact:
prefix_id: "{{ item.id }}"
loop: "{{ gather_prefixes_result.json.results }}"
when:
- item.prefix == target_prefix
- when: prefix_id is defined
block:
- name: "Gather available ips info from NetBox"
uri:
url: "{{ netbox_url }}/{{ prefix_id }}/available-ips/"
register: gather_available_ips_result
- debug: var=gather_available_ips_result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment