Skip to content

Instantly share code, notes, and snippets.

@DevoKun
Last active September 21, 2022 06:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DevoKun/c72cd08230836c089eb6f1c735ecb040 to your computer and use it in GitHub Desktop.
Save DevoKun/c72cd08230836c089eb6f1c735ecb040 to your computer and use it in GitHub Desktop.
Ansible Gather Facts from Azure VM Metadata
---
- hosts: localhost
pre_tasks:
- name: "apt install curl"
apt:
name: curl
state: latest
when: ansible_os_family == "Debian"
- name: "yum install curl"
yum:
name: curl
state: present
when: (ansible_os_family == "RedHat")
- name: "get metadata"
shell: "curl -H Metadata:true http://169.254.169.254/metadata/instance?api-version=2017-04-02"
register: azure_metadata
- name: "set azure_metadata"
set_fact:
azure_metadata: "{{ azure_metadata.stdout | from_json }}"
tasks:
- debug:
msg:
- "####################################"
- "## eastus: {{ azure_metadata.compute.location }}"
- "####################################"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment