0
我試圖在衆多實例(使用特定名稱)上使用Ansible的裝配模塊裝入一堆卷,並且需要一種方法請確保我可以檢查正在解析的卷是否正在裝入正確的實例。如何使用Ansible標記具有其實例的私有IP地址的卷使用Ansible
我遇到的問題是,如果我有兩臺主機和這些主機的實例信息(包括卷ID),它會嘗試將所有卷掛載到兩臺主機上,實際上我需要檢查會阻止這一點。
我希望能夠使用已經連接到的實例的IP地址來標記卷。我可以用一個實例來做到這一點,但它不具有多個實例的工作...
有了一個實例:
- name: Tag the EBS Volumes
hosts: datanodes
gather_facts: False
tags: tag
vars_files:
- /etc/ansible/defaults.yml
tasks:
- setup:
filter: ansible_mounts
- name: Gather datanodes instance instance_ids
local_action:
module: ec2_remote_facts
region: '{{ aws_region }}'
filters:
instance-state-name: running
"tag:Type": datanodes
register: dn_id
- name: Verify that the datanodes instance is running...
local_action:
module: ec2
region: '{{ aws_region }}'
instance_ids: '{{ item.id }}'
state: running
wait: True
vpc_subnet_id: '{{ vpc_subnet_id }}'
tags: start
register: ec2
with_items: "{{ dn_id.instances }}"
- debug: var=ec2
- name: Gather volume information for dn instance
local_action:
module: ec2_vol
region: '{{ aws_region }}'
instance: '{{ item.id }}'
state: list
register: volume
with_items: "{{ ec2.results[0].instances }}"
- name: tag the volumes with their correct instance IP Address
local_action:
module: ec2_tag
resource: '{{ item.1.id }}'
region: "{{ aws_region }}"
tags:
CurrentIP: '{{ item.0 }}'
#DeviceName: '{{ item.0 }}'
#VolumeId: '{{ item.1.volume_id }}'
#MountName: '{{ item.1.mount }}'
with_nested:
- "{{ groups.datanodes }}"
- "{{ volume.results[0].volumes }}"
- name: tag the volumes with the universal volume Id (everyone gets this one)
local_action:
module: ec2_tag
resource: '{{ item.0.id }}'
region: "{{ aws_region }}"
tags:
home_id: '{{ item.1.id }}'
#CurrentIP: '{{ item.0 }}'
#DeviceName: '{{ item.0 }}'
#VolumeId: '{{ item.1.volume_id }}'
#MountName: '{{ item.1.mount }}'
with_nested:
- "{{ volume.results[0].volumes }}"
- "{{ volume.results[0].volumes }}"
when: item.device_name | search("/dev/sd")
我將如何做到這一點有多個實例?如果你有一個更好的方法來完成那個非常棒的節點。此外,我需要它儘可能動態,所以我不能只使用/dev/sdb
和/mount1
爲每個名稱...
D你想擴展到多個主機?不確定你的意思是'儘可能動態' – helloV
是的!!!!!!對不起 – Cloudish123
實際上,有多個ec2實例。這將使我可以掛載多個主機的卷。 – Cloudish123