[英]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
. mount
和setup
。
Something like:就像是:
- include_tasks: partition-mount-and-setup.yml
loop: "{{ mounts }}"
And in partition-mount-and-setup.yml , something like在partition-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.