AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 911257
Accepted
Shailesh Sutar
Shailesh Sutar
Asked: 2018-05-09 03:39:36 +0800 CST2018-05-09 03:39:36 +0800 CST 2018-05-09 03:39:36 +0800 CST

Ansible:格式化文件系统子任务失败

  • 772

我有以下任务在格式化 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
filesystems
  • 1 1 个回答
  • 492 Views

1 个回答

  • Voted
  1. Best Answer
    Henrik Pingel
    2018-05-10T00:05:02+08:002018-05-10T00:05:02+08:00

    要格式化和挂载卷,Ansible 需要针对新创建的 ec2 实例运行。这样的事情应该可以解决问题:

    [...]
    - name: Add all instance public IPs to host group
      add_host: hostname={{ item.public_ip }} groups=ec2hosts
      loop: "{{ ec2.instances }}"
    
    - hosts: ec2hosts
      name: configuration play
      user: ec2-user
    
      tasks:
       - name: Format data volume
       [...]
    
    • 1

相关问题

  • 我如何知道 AIX 中磁盘上的文件系统是什么?

  • 控制 UNIX 目录内容用户组所有权

  • 在 Ubuntu 上将 Windows 磁盘分区与 Linux 分区合并

  • 在 VMPlayer 上 Windows 和 Linux 之间共享目录的最佳方式

  • md5sum 重复为同一台机器上的同一文件提供不同的校验和

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve