How to create a new partition with Ansible

前端 未结 4 1016
走了就别回头了
走了就别回头了 2021-02-05 09:53

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

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

But in Ansible it does not want to ru

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 10:31

    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.

    Try:

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

    Or:

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

提交回复
热议问题