Skip to content

Instantly share code, notes, and snippets.

@matthewcosgrove
Last active January 12, 2021 11:08
Show Gist options
  • Save matthewcosgrove/3ba38b2c8e23973f98514549971e6900 to your computer and use it in GitHub Desktop.
Save matthewcosgrove/3ba38b2c8e23973f98514549971e6900 to your computer and use it in GitHub Desktop.
TMPDIR=""¬
TMPDIR=$(mktemp -d -t dynamic_inventory.XXXXXX)
trap 'rm -rf ${TMPDIR}' INT TERM QUIT EXIT
INVENTORY_FILE="${TMPDIR}"/inventory.yml
cat <<EOF > "${INVENTORY_FILE}"
all:
hosts:
${IP_ADDRESS}:
ansible_python_interpreter: /usr/bin/python3
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
validate_certs: no
idrac_ip: "{{ inventory_hostname }}"
idrac_user: "{{ lookup('env', 'IDRAC_USER') }}"
idrac_password: "{{ lookup('env', 'IDRAC_PASSWORD') }}"
EOF
ansible --version
ansible-inventory -i "${INVENTORY_FILE}" --list | grep -v password
ansible -i "${INVENTORY_FILE}" -m ping all
# Don't use meta/main.yml to define dependencies
# https://www.reddit.com/r/ansible/comments/hefazd/molecule_and_role_dependencies/
---
- name: PoC for firmware inventory
hosts: all
connection: local
collections:
- dellemc.openmanage
tasks:
- name: Get Installed Firmware Inventory
dellemc_get_firmware_inventory:
idrac_ip: "{{ idrac_ip }}"
idrac_user: "{{ idrac_user }}"
idrac_password: "{{ idrac_password }}"
register: installed_firmware
- name: Extract json
set_fact:
firmware_json: installed_firmware.ansible_facts['{{ idrac_ip }}']["Firmware Inventory"].Firmware
- name: Debug firmware json
ansible.builtin.debug:
var: firmware_json
- name: Copy fo file
ansible.builtin.copy:
content: "{{ installed_firmware.ansible_facts }}"
dest: "/tmp/ansible_facts_idrac_{{ inventory_hostname }}.json"
if ! pip3 list --format=legacy | grep omsdk;then
pip3 install omsdk --upgrade
fi
ansible-galaxy collection install dellemc.openmanage
# playbook
cat /tmp/ansible_facts_idrac_"${IDRAC_IP}".json | gron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment