Last active
September 21, 2022 06:02
-
-
Save DevoKun/c72cd08230836c089eb6f1c735ecb040 to your computer and use it in GitHub Desktop.
Ansible Gather Facts from Azure VM Metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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