I have a question abour AWS EBS, how aws’s attach a volumes to instance ? i have cloudinit script to formatt and mount a volume but does’t work because device not found i think that cloudinit script faster than volume attach (when i connect to machine and try to format and mount disk it work for me OR when i do this with UI ) ?
2019-08-22 13:59:33,964 - helpers.py[DEBUG]: Running config-disk_setup using lock (<FileLock using file '/var/lib/cloud/instances/i-0547294074e102618/sem/config_disk_setup'>)
2019-08-22 13:59:33,965 - DataSourceEc2.py[DEBUG]: Unable to convert /dev/xvdf to a device
2019-08-22 13:59:33,965 - cc_disk_setup.py[DEBUG]: Partitioning disks: {'/dev/xvdf': {'layout': True, 'overwrite': False, 'table_type': 'mbr'}}
2019-08-22 13:59:33,965 - cc_disk_setup.py[DEBUG]: Creating new partition table/disk
2019-08-22 13:59:33,965 - util.py[DEBUG]: Running command ['udevadm', 'settle'] with allowed return codes [0] (shell=False, capture=True)
2019-08-22 13:59:33,981 - util.py[DEBUG]: Creating partition on /dev/xvdf took 0.016 seconds
2019-08-22 13:59:33,981 - util.py[WARNING]: Failed partitioning operation
Device /dev/xvdf did not exist and was not created with a udevamd settle.
2019-08-22 13:59:33,981 - util.py[DEBUG]: Failed partitioning operation
Device /dev/xvdf did not exist and was not created with a udevamd settle.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/config/cc_disk_setup.py", line 140, in handle
func=mkpart, args=(disk, definition))
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 2514, in log_time
ret = func(*args, **kwargs)
File "/usr/lib/python3/dist-packages/cloudinit/config/cc_disk_setup.py", line 769, in mkpart
assert_and_settle_device(device)
File "/usr/lib/python3/dist-packages/cloudinit/config/cc_disk_setup.py", line 746, in assert_and_settle_device
"with a udevamd settle." % device)
RuntimeError: Device /dev/xvdf did not exist and was not created with a udevamd settle.2019-08-22 13:59:33,995 - cc_disk_setup.py[DEBUG]: setting up filesystems: [{'device': '/dev/xvdf1', 'filesystem': 'ext4', 'label': 'data', 'partition': 'auto'}]
2019-08-22 13:59:33,995 - DataSourceEc2.py[DEBUG]: Unable to convert /dev/xvdf1 to a device
2019-08-22 13:59:33,995 - cc_disk_setup.py[DEBUG]: Creating new filesystem.
2019-08-22 13:59:33,995 - util.py[DEBUG]: Running command ['udevadm', 'settle'] with allowed return codes [0] (shell=False, capture=True)
2019-08-22 13:59:34,012 - util.py[DEBUG]: Creating fs for /dev/xvdf1 took 0.017 seconds
2019-08-22 13:59:34,012 - util.py[WARNING]: Failed during filesystem operation
Device /dev/xvdf1 did not exist and was not created with a udevamd settle.
2019-08-22 13:59:34,012 - util.py[DEBUG]: Failed during filesystem operation
Device /dev/xvdf1 did not exist and was not created with a udevamd settle.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/config/cc_disk_setup.py", line 158, in handle
func=mkfs, args=(definition,))
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 2514, in log_time
ret = func(*args, **kwargs)
File "/usr/lib/python3/dist-packages/cloudinit/config/cc_disk_setup.py", line 871, in mkfs
assert_and_settle_device(device)
File "/usr/lib/python3/dist-packages/cloudinit/config/cc_disk_setup.py", line 746, in assert_and_settle_device
"with a udevamd settle." % device)
RuntimeError: Device /dev/xvdf1 did not exist and was not created with a udevamd settle.
2019-08-22 13:59:34,013 - handlers.py[DEBUG]: finish: init-network/config-disk_setup: SUCCESS: config-disk_setup ran successfully
2019-08-22 13:59:34,013 - stages.py[DEBUG]: Running module mounts (<module 'cloudinit.config.cc_mounts' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_mounts.py'>) with frequency once-per-instance
2019-08-22 13:59:34,013 - handlers.py[DEBUG]: start: init-network/config-mounts: running config-mounts with frequency once-per-instance
2019-08-22 13:59:34,013 - util.py[DEBUG]: Writing to /var/lib/cloud/instances/i-0547294074e102618/sem/config_mounts - wb: [644] 24 bytes
2019-08-22 13:59:34,014 - helpers.py[DEBUG]: Running config-mounts using lock (<FileLock using file '/var/lib/cloud/instances/i-0547294074e102618/sem/config_mounts'>)
2019-08-22 13:59:34,014 - cc_mounts.py[DEBUG]: mounts configuration is [['/dev/xvdf1', '/data', 'auto', 'defaults,nofail', '0', '0']]
2019-08-22 13:59:34,014 - util.py[DEBUG]: Reading from /etc/fstab (quiet=False)
2019-08-22 13:59:34,014 - util.py[DEBUG]: Read 51 bytes from /etc/fstab
2019-08-22 13:59:34,014 - cc_mounts.py[DEBUG]: Attempting to determine the real name of /dev/xvdf1
2019-08-22 13:59:34,014 - cc_mounts.py[DEBUG]: changed /dev/xvdf1 => None
2019-08-22 13:59:34,014 - cc_mounts.py[DEBUG]: Ignoring nonexistent named mount /dev/xvdf1
2019-08-22 13:59:34,014 - cc_mounts.py[DEBUG]: Attempting to determine the real name of ephemeral0
and here is my code
locals {
disk = {
name = "/dev/sdf"
label = "data"
device = "/dev/xvdf"
partition = "/dev/xvdf1"
filesystem = "ext4"
mount_dir = "/data"
}
users = [
{
user_name = "demo"
passwd = ""
},
]
}
data "template_file" "script" {
template = "${file("../../../terraform/templates/cloudinit_templates/cloudinit.yml.tpl")}"
vars = {
users = jsonencode(local.users)
disk = jsonencode(local.disk)
}
}
and my template file
#cloud-config
users:
- default
%{ for user in jsondecode(users) ~}
- name: ${user.user_name}
groups: [ root ]
sudo: [ "ALL=(ALL) NOPASSWD:ALL" ]
shell: /bin/bash
lock_passwd: false
passwd: ${user.passwd}
ssh_authorized_keys:
- ${user.ssh_authorized_keys}
%{ endfor ~}
disk_setup:
${lookup(jsondecode(disk), "device", "_",)}:
table_type: 'mbr'
layout: True
overwrite: False
fs_setup:
- label: ${lookup(jsondecode(disk), "label", "_",)}
filesystem: '${lookup(jsondecode(disk), "filesystem", "_",)}'
device: '${lookup(jsondecode(disk), "partition", "_",)}'
partition: auto
mounts:
- [${lookup(jsondecode(disk), "partition", "_",)}, ${lookup(jsondecode(disk), "mount_dir", "_",)}, "auto", "defaults,nofail", "0", "0"]