如何使用 Ansible 创建新分区 [英] How to create a new partition with Ansible

查看:31
本文介绍了如何使用 Ansible 创建新分区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在命令行上运行它时它工作正常:

When I run this on the command line it works fine:

 echo -e "n\np\n1\n\n\nw" | sudo fdisk /dev/sdb

但在 Ansible 中它不想在 shell 中运行:

But in Ansible it does not want to run in shell:

 - name: partition new disk
   shell: echo -e "n\np\n1\n\n\nw" | sudo fdisk /dev/sdb

它不会返回错误,但也不会创建分区.

It does not come back with an error, but it does not create the partition either.

我检查过 Ansible 和 LVM 不会做我需要的.

I checked that Ansible and LVM will not do what I need.

有什么建议吗?

推荐答案

默认情况下,Ansible 执行 /bin/sh shell.
例如,如果 /bin/sh 链接到 dash,它构建的 echobash 中的不同> 或 GNU echo;所以你最终将 -e 字符输入到 fdisk.

By default, Ansible executes /bin/sh shell.
For example, if /bin/sh is linked to dash, it's built echo is different to the one in bash or GNU echo; so you end up with -e characters fed into fdisk.

试试:

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

或者:

- name: partition new disk
  shell: /bin/echo -e "n\np\n1\n\n\nw" | sudo fdisk /dev/sdb

这篇关于如何使用 Ansible 创建新分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆