User Tools

Site Tools


ansible-metadata

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ansible-metadata [2020/10/01 17:15] (current)
ian created
Line 1: Line 1:
 +====== Get VM Metadata with Ansible ======
  
 +I needed to get VM Metadata and store it in a variable I could use later as a ''{{ variable }}'' in an Ansible playbook.
 +
 +<code>
 +  pre_tasks:
 +    - name: Get ResourceGroup name from metadata service
 +      uri:
 +        url: http://169.254.169.254/metadata/instance/compute/resourceGroupName?api-version=2017-08-01&format=text
 +        headers:
 +          metadata: true
 +        return_content: yes
 +      register: resourcegroup
 +    - debug:
 +        var: resourcegroup.content
 +</code>
 +
 +I was then able to reference the resourceGroup name
 +
 +<code>
 +configuration_variable: "{{ resourcegroup.content | lower }}"
 +</code>
ansible-metadata.txt ยท Last modified: 2020/10/01 17:15 by ian

free spam filter