Repository URL to install this package:
Version:
6.0.0 ▾
|
---
#
# Summary: Auto generate (or update) the Ansible inventory file with Standalone C-Series servers (Name and Moid or each discovered server)
#
# The hosts group used is provided by the group variable or defaulted to 'Intersight'.
# You can specify a specific host (or host group) on the command line:
# ansible-playbook ... -e group=<your host group>
# e.g., ansible-playbook server_profiles.yml -e group=TME_Demo
#
# This playbook only runs once (and not for each server in the inventory), but the hosts group is used to get API key info
#
- hosts: "{{ group | default('Intersight') }}"
connection: local
gather_facts: false
vars:
# Create an anchor for api_info that can be used throughout the file
api_info: &api_info
# if api_key vars are omitted, INTERSIGHT_API_KEY_ID, INTERSIGHT_API_PRIVATE_KEY,
# and INTERSIGHT_API_URI environment variables used for API key data
api_private_key: "{{ api_private_key | default(omit) }}"
api_key_id: "{{ api_key_id | default(omit) }}"
api_uri: "{{ api_uri | default(omit) }}"
validate_certs: "{{ validate_certs | default(omit) }}"
state: "{{ state | default(omit) }}"
# How many results to return per inventory file
per_page: 500
# Total servers to query
max_servers: 15000
# Change filepath if you want to update a different inventory file
filepath: "{{ inventory_file }}"
# Change host_group if you want to use another group name for your servers in the created inventory
host_group: Intersight_Servers
tasks:
# Enclose tasks in a block that is only run once
- block:
# Set an api response for the 1st loop iteration
- set_fact:
servers:
api_response:
- Moid: fake
run_once: true
# Find all servers
- cisco.intersight.intersight_rest_api:
<<: *api_info
resource_path: /compute/PhysicalSummaries
query_params:
$filter: "ManagementMode eq 'IntersightStandalone' and contains(Model, 'UCSC-C')"
$select: Name,Model,Serial
$top: "{{ per_page }}"
$skip: "{{ item }}"
return_list: true
loop: "{{ range(0, max_servers|int, per_page|int) | list }}"
register: servers
when: servers.api_response
# Place the servers in a group in the file
- debug:
msg: Inventory filepath "{{ filepath }}"
- lineinfile:
path: "{{ filepath }}"
line: "[{{ host_group }}]"
create: true
- include_tasks: servers_to_file.yml
loop: "{{ servers.results }}"
loop_control:
loop_var: outer_item
delegate_to: localhost
run_once: true