我有以下任务在格式化 EBS 卷时失败,只是不再继续。我已经检查了这里的所有文档,但我发现我在这里定义的 ansible 任务没有问题。
---
# tasks file for aws-create-ec2
- name: Set instance file system path when instance type is i3.*
set_fact:
data_volume_fspath: /dev/nvme0n1
when: "aws_create_ec2.instance_type is search('i3.*')"
register: data_volume_fspath
- name: create an ec2 instance
ec2:
vpc_subnet_id: "{{ aws_create_ec2.vpc_subnet_id }}"
key_name: "{{ aws_create_ec2.ec2_key_name }}"
instance_type: "{{ aws_create_ec2.instance_type }}"
image: "{{ aws_create_ec2.aws_ami }}"
region: "{{ aws_create_ec2.region }}"
aws_access_key: "{{ aws_create_ec2.aws_access_key }}"
aws_secret_key: "{{ aws_create_ec2.aws_secret_key }}"
count: "{{ aws_create_ec2.node_count }}"
instance_tags:
Name: "{{ aws_create_ec2.node_name }}"
created_by: ansible
group: "{{ aws_create_ec2.aws_security_group_name }}"
assign_public_ip: "{{ aws_create_ec2.assign_public_ip }}"
register: ec2
- name: Add new instances to a host group
add_host: name={{ item.1.private_dns_name }} groups=just_created
with_indexed_items: "{{ ec2.instances }}"
- name: Wait for SSH to come up
wait_for: host={{ item.private_dns_name }} port=22 delay=60 timeout=360 state=started
with_items: "{{ ec2.instances }}"
- name: Make sure the local known hosts file exists
file: "path=~/.ssh/known_hosts state=touch"
- name: Scan the public key of the new host and add it to the known hosts
shell: "ssh-keyscan -H -T 10 {{ item.private_ip }} >> ~/.ssh/known_hosts"
with_items: "{{ ec2.instances }}"
- name: Wait for instance bootup
pause:
minutes: 2
- name: Setup EBS volume when instance type is t2.*
ec2_vol:
instance: "{{ item.id }}"
volume_size: "{{ aws_create_ec2.volume_size }}"
device_name: "{{ aws_create_ec2.device_name }}"
volume_type: "{{ aws_create_ec2.volume_type }}"
region: "{{ aws_create_ec2.region }}"
delete_on_termination: true
with_items: "{{ ec2.instances }}"
when: "aws_create_ec2.instance_type is search('t2.*')"
- name: Wait for volume to be available
pause:
minutes: 1
- name: Format data volume
become: true
become_method: sudo
filesystem:
fstype: "{{ aws_create_ec2.data_volume_fstype }}"
dev: "{{ aws_create_ec2.data_volume_fspath }}"
force: no
when: "aws_create_ec2.instance_type is search('t2.*')"
- name: Mount data volume
become: true
become_method: sudo
mount:
name: "{{ aws_create_ec2.data_volume_mountpoint }}"
src: "{{ aws_create_ec2.data_volume_fspath }}"
fstype: "{{ aws_create_ec2.data_volume_fstype }}"
state: mounted
when: "aws_create_ec2.instance_type is search('t2.*')"
以下是我为该任务遇到的错误,但卷已创建并附加到 ec2 实例。我不确定这里有什么问题。有人可以指出我正确的方向。我正在传递group_vars/all.yml
文件中的所有值,并且所有内容都在那里定义。Format Data volume
子任务失败并给出以下错误。
"msg": "Device /dev/xvdb not found."
例如,当我检查它时它就在那里/dev/xvdb
Disk /dev/xvdb: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
要格式化和挂载卷,Ansible 需要针对新创建的 ec2 实例运行。这样的事情应该可以解决问题: