V
V
Vadim2019-05-22 20:25:33
Automation
Vadim, 2019-05-22 20:25:33

How to iterate through all instances and display all connected disk IDs and IP addresses using Ansible?

There is a Playbook trail, just the beginning:
---
# Ansible facts
- name: Get Information about Instances
hosts: localhost
# become: yes
gather_facts: False
vars:
volu: tempo
tasks:
- name: Get Information about Instance
ec2_instance_facts:
filters:
vpc- id: vpc-76d4dqw2
register: ec2_facts
- set_fact:
volu2: "{{ ec2_facts.instances[0].block_device_mappings[0].ebs.volume_id }}"
- debug: var=volu2
Tell me how you can use with_items to go through all the instances in the VPC and write everything to separate variables. Preferably with a new playbook challenge. For example, import new_playbook, where they will be processed
Regards

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Puma Thailand, 2019-05-22
@opium

So ansible collects facts about all nodes, and facts are variables.
There are IP and disks.

O
OnYourLips, 2019-05-22
@OnYourLips

If you need a complex structure, then I would write my own module.
This is very easy to do:
https://habrahabr.ru/company/d2cio/blog/348118/
library/mymodule.py
roles/myrole/library/mymodule.py
https://docs.ansible.com/ansible/latest/dev_guide /...

I
Ivan Shumov, 2019-05-22
@inoise

But the magic 169.254.169.254/latest/meta-data will not help you?) There is a lot of useful stuff in my memory

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question