Skip to content

Instantly share code, notes, and snippets.

@DevoKun
Last active September 21, 2022 06:02
Show Gist options
  • Save DevoKun/c72cd08230836c089eb6f1c735ecb040 to your computer and use it in GitHub Desktop.
Save DevoKun/c72cd08230836c089eb6f1c735ecb040 to your computer and use it in GitHub Desktop.

Revisions

  1. DevoKun revised this gist Apr 18, 2019. No changes.
  2. DevoKun created this gist Apr 18, 2019.
    34 changes: 34 additions & 0 deletions gather_facts_from_azure_vm_metadata.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    ---

    - 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 }}"
    - "####################################"