gpt4 book ai didi

azure - 如何使用数据磁盘创建Azure vm,然后通过ansible对其进行格式化

转载 作者:行者123 更新时间:2023-12-02 06:46:37 26 4
gpt4 key购买 nike

我可以单独进行操作,但无法将它们组合在一起,因为我不知道磁盘设备名称。

我的配置:

- name: Create Virtual Machine
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ item }}"
vm_size: "{{ flavor }}"
managed_disk_type: "{{ disks.disk_type }}"
network_interface_names: "NIC-{{ item }}"
ssh_password_enabled: false
admin_username: "{{ cloud_config.admin_username }}"
image:
offer: "{{ image.offer }}"
publisher: "{{ image.publisher }}"
sku: "{{ image.sku }}"
version: "{{ image.version }}"
tags:
Node: "{{ tags.Node }}"
ssh_public_keys:
- path: "/home/{{ cloud_config.admin_username }}/.ssh/authorized_keys"
key_data: "{{ cloud_config.ssh.publickey }}"
data_disks:
- lun: 0
disk_size_gb: "{{ disks.disk_size }}"
caching: "{{ disks.caching }}"
managed_disk_type: "{{ disks.disk_type }}"

格式化和挂载磁盘的其他部分

- name: partition new disk
shell: 'echo -e "n\np\n1\n\n\nw" | fdisk /dev/sdc'
args:
executable: /bin/bash

- name: Makes file system on block device
filesystem:
fstype: xfs
dev: /dev/sdc1

- name: new dir to mount
file: path=/hadoop state=directory

- name: mount the dir
mount:
path: /hadoop
src: /dev/sdc1
fstype: xfs
state: mounted

我的问题:设备名称无法配置。它可以是/dev/sdc 或/dev/sdb。对于AWS ec2,我可以设置卷[device_name],但我在Azure中找不到这样的字段。我该如何解决它?

最佳答案

/dev/sdb默认用于临时磁盘,但有时它被我的数据盘使用。我找到了一种解决方法,可以在格式化之前检查设备名称。我知道这不是一个聪明的方法。

- name: check device name which should be parted
shell: parted -l
register: device_name

- name: Show middle device name
debug:
msg: "{{ device_name.stderr.split(':')[1] }}"
register: mid_device

- name: Display real device name
debug:
msg: "{{ mid_device.msg.split()[0] }}"
register: real_device

- name: partition new disk
shell: 'echo -e "n\np\n1\n\n\nw" | fdisk {{ real_device.msg }}'
args:
executable: /bin/bash

- name: Makes file system on block device
filesystem:
fstype: xfs
dev: "{{ real_device.msg }}1"

- name: new dir to mount
file: path=/hadoop state=directory

- name: mount the dir
mount:
path: /hadoop
src: "{{ real_device.msg }}1"
fstype: xfs
state: mounted

关于azure - 如何使用数据磁盘创建Azure vm,然后通过ansible对其进行格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49424967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com