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

查看:207
本文介绍了如何使用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天全站免登陆