简体   繁体   English

如何重新收集设备信息以删除任何分区磁盘?

[英]How do I re-gather device facts to remove any partitioned disks?

I'm building a role for which I'm trying to gather disks without any partitions using我正在构建一个角色,我试图为其收集磁盘而不使用任何分区

disks: "{{ ansible_devices | dict2items | selectattr('key', 'match', '^sd.*')  |  selectattr('value.partitions', 'match', '{}' )  | list  }}"

and then mount on the partition.然后挂载到分区上。 But, as I'm running over a loop I wanted to update the list/disks when the mount and partition is completed.但是,当我运行一个循环时,我想在挂载和分区完成时更新列表/磁盘。

For example, if my list at the start looks like例如,如果一开始我的列表看起来像

disks: [sdb,sdc,sdd,sde]

when the partitioning and mounting on sdb using the mount module in Ansible is done, the list should be updated and look something like this当使用 Ansible 中的mount模块在sdb上分区和挂载完成时,列表应该更新并且看起来像这样

disks: [sdc,sdd,sde]

How can I achieve this?我怎样才能做到这一点?

You should be able to refresh the facts by calling the setup module after your mounts.您应该能够通过在安装后调用setup模块来刷新事实。

So, a plain and simple task reading:因此,一个简单明了的任务阅读:

- setup:

And Ansible will gather the facts of the host(s) again, so, your partition list should be up-to-date.而 Ansible 将再次收集主机的信息,因此,您的分区列表应该是最新的。


Since you cannot do it in the task itself, what you could do, in your role is to have an include_tasks that would make an unicity of the tasks: parted (or whatever you are using to partition);由于您不能在任务本身中执行此操作,因此您可以做的是,在您的角色中有一个include_tasks可以使任务具有唯一性: parted (或您用于分区的任何内容); mount and setup . mountsetup

Something like:就像是:

- include_tasks: partition-mount-and-setup.yml
  loop: "{{ mounts }}"

And in partition-mount-and-setup.yml , something likepartition-mount-and-setup.yml中,类似

- parted:
    device: "{{ item.mount_point }}"
    number: 1
    state: present
    part_end: "{{ item.size }}"

- mount:
    src: "{{ item.mount_point }}"
    path: "/mnt/{{ item.mount_point }}"
    state: mounted
    fstype: ext2

- setup:

All this is untested, but you could just follow the general logic所有这些都未经测试,但您可以遵循一般逻辑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Ansible在未知计算机上收集所有事实? - How to gather all facts on an unknown machine with Ansible? 在一本 Ansible 剧本中安装 Python 后如何收集事实? - How to gather facts after installing Python in one Ansible playbook? 如何删除 Kubernetes 部署中的所有磁盘? - How do I delete all the disks in a deployment in Kubernetes? 如何使用pydocumentdb在Cosmos DB中创建分区集合? - How do I create a partitioned collection in Cosmos DB with pydocumentdb? 如何使用自定义标头从 pandas 中的 3 个数据帧收集信息? - How do I gather information from 3 dataframes in pandas with custom headers? 使用 python 代码如何获取 azure 中的磁盘名称和磁盘状态 - Using python code how do i get the disks name and disk state in azure 如何使用 re.sub 删除方括号内的重复文本块? - How do I use re.sub to remove a repeated block of text within square brackets? 在 python pandas 中应用样式后,如何删除和重新排序(重新索引)列? - How do I remove and re-sort (reindex) columns after applying style in python pandas? 如何在不使用 remove() 或任何其他函数的情况下从列表中删除元素 - How do i remove elements from a list without using remove(), or any other functions 如何对 asyncio.gather() 收集的异常执行 logging.exception()? - How do I do logging.exception() on exceptions gathered by asyncio.gather()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM