How to create a new partition with Ansible

前端 未结 4 1018
走了就别回头了
走了就别回头了 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:40

    With Ansible 2.3 and above, you can use parted module to create partitions from a block device. For example:

     - parted:
         device: /dev/sdb
         number: 1
         flags: [ lvm ]
         state: present
    

    To format the partition just use filesystem module as shown below:

     - filesystem:
         fstype: ext2
         dev: /dev/sdb1
    

    To mount the partition to, let's say, /work folder just use mount module as shown below:

    - mount:
        fstype: ext2
        src: /dev/sdb1
        path: /work
        state: mounted
    

提交回复
热议问题