How to create a new partition with Ansible

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

    How to allocate all free space to a new partition and add it to LVM in Ansible

    • If you're using LVM, look into this!

    • If you want to use all the free space of the device, look into this!

    Starting with a device /dev/sda and an existing partition on /dev/sda1 in {{ volumeGroup }}.

    Use the following approach to create a partition /dev/sda2 in the free space of /dev/sda and to subsequently add the new partition to the existing {{ volumeGroup }}

    - name: "Create partitions on devices"    
      block:   
        - name: install parted
          package:
            name: parted
            state: present 
            
        - name: "Read device information /dev/sda"
          parted: 
            device: "/dev/sda"
            unit: MiB
          register: device_info
        
        - name: "Add new partition /dev/sda2"
          parted: 
            device: "/dev/sda"
            number: "2"
            part_type: primary
            flags: [ lvm ]
            state: present
            part_end: "100%"
            part_start: "{{ device_info.partitions[0].end + 1}}MiB" 
            
        - name: "Add device to exising volume group {{ volumeGroup }}."
          lvg:
            vg: "{{ volumeGroup }}"
            pvs: "/dev/sda1,/dev/sda2"
     
    

提交回复
热议问题