HiveBrain v1.2.0
Get Started
← Back to all entries
snippetModerate

Ansible how to know what return value is provided by a specific module

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
knowwhatreturnspecificmoduleprovidedvaluehowansible

Problem

From Ansible's official doc


Ansible modules normally return a data structure that can be registered into a variable, or seen directly when output by the ansible program

and


Ansible modules normally return a data structure that can be registered into a variable, or seen directly when output by the ansible program

However, the document on aws_ec2 module

  • Doesn't document return values



  • Has this example, which seems like it actually has some specific return values



# Stripped version

# Launch instances, runs some tasks
# and then terminate them

- name: Create a sandbox instance
  ... # hosts, vars...
  tasks:
    - name: Launch instance
      ec2:
      ... # ec2 module specs
      register: ec2 #This seems to be one of the specific return structure by this module

    - name: Wait for SSH to come up
      ... # some module
      with_items: "{{ ec2.instances }}" # This is where the registered return value is used


Question: How to see all possible return values of a module, even without documentation

Solution

if you do something like:

- name: Launch instance
  ec2:
  register: data_struct


You can then output all the values returned by doing this below the above code:

- name: print all returned values
  debug:
    msg: "{{ data_struct }}"

Code Snippets

- name: Launch instance
  ec2:
  register: data_struct
- name: print all returned values
  debug:
    msg: "{{ data_struct }}"

Context

StackExchange DevOps Q#5921, answer score: 10

Revisions (0)

No revisions yet.