Ansible syntax error : unexpected parameter type in action: class 'ansible.parsing.yaml.objects.AnsibleSequence'

huangapple go评论158阅读模式
英文:

Ansible syntax error : unexpected parameter type in action: class 'ansible.parsing.yaml.objects.AnsibleSequence'

问题

以下是翻译好的部分:

- name: '分区'
  tags: ['fs', 'fs-ext4']
  vars:
    vdcnames: 'ls -l /dev/disk/by-id | grep "{{volume[items["name"]]}}" | head -1 | cut -d "/" -f 1'
  tasks:
    - name: '获取vdcnames值'
      shell:
        cmd: '{{ vdcnames }}'
      register: 'vdcnames_out'
      loop: '{{ volumes.results }}'
      loop_control:
        label: '{{ items.name }}'
      when:
        - 'not items.skipped | d(False)'
        - 'items["drive"]["name"] | d("") == "trwer"'
        - 'items["partitions"] | d([]) | count == 1'

    - name: '调整分区大小'
      shell: |
        sgdisk -e {{ items.device | d( volume[items["name"]] ) }} &&
        parted -m -s -a opt {{ items.device | d( vdcnames_out.stdout ) }} resizepart 1 100%        
      loop: '{{ volumes.results }}'
      loop_control:
        label: '{{ items.name }}'

请注意,我已经根据您提供的原始代码进行了翻译,但是代码本身可能存在问题。如果您在运行代码时仍然遇到问题,请确保检查代码的逻辑和语法是否正确。

英文:
- name: 'Partition'
  tags: ['fs', 'fs-ext4']
  vars:
    vdcnames: 'ls -l /dev/disk/by-id | grep "{{volume[items["name"]]}}" | head -1 | cut -d "/" -f 1'
  tasks:
    - name: 'Get vdcnames value'
      shell:
        cmd: '{{ vdcnames }}'
      register: 'vdcnames_out'
    - name: 'Resizing the partition'
      shell:
        cmd: >
          sgdisk -e {{ items.device | d( volume[items["name"]] ) }} &&
          parted -m -s -a opt {{ items.device | d( vdcnames_out.stdout ) }} resizepart 1 100%
  when:
    - 'not items.skipped | d(False)'
    - 'items["drive"]["name"] | d("") == "trwer"'
    - 'items["partitions"] | d([]) | count == 1'
  loop: '{{ volumes.results }}'
  loop_control:
    label: '{{ items.name }}'

Above code is in roles/abc/main.yml. I was getting the below error for the above code

ERROR! unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'>

The error appears to be in '/roles/abc/main.yml': line 20, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:
- name: 'Partition'
  ^ here

I modified the code for resolving the syntax issue as below but still the same error

- name: 'Partition'
  tags: ['fs', 'fs-ext4']
  vars:
    vdcnames: 'ls -l /dev/disk/by-id | grep "{{volume[items["name"]]}}" | head -1 | cut -d "/" -f 1'
  tasks:
    - name: 'Get vdcnames value'
      shell:
        cmd: '{{ vdcnames }}'
      register: 'vdcnames_out'
      loop: '{{ volumes.results }}'
      loop_control:
        label: '{{ items.name }}'
      when:
        - 'not items.skipped | d(False)'
        - 'items["drive"]["name"] | d("") == "trwer"'
        - 'items["partitions"] | d([]) | count == 1'
    
    - name: 'Resizing the partition'
      shell: |
        sgdisk -e {{ items.device | d( volume[items["name"]] ) }} &&
        parted -m -s -a opt {{ items.device | d( vdcnames_out.stdout ) }} resizepart 1 100%
      loop: '{{ volumes.results }}'
      loop_control:
        label: '{{ items.name }}'

I was trying to resize the disk through ansible but facing this error. Can someone please help me what's exactly the error is?
I tried a lot for resolving this by modifying the code but error is still the same, not sure why.

答案1

得分: 1

不知道这是否有帮助。但自Ansible 2.0以来,文件系统模块中有一个名为resizefs的选项,默认值为false,支持ext4文件系统。

如果是的话,如果块设备和文件系统大小不同,将文件系统扩展到可用空间。支持的文件系统包括ext2、ext3、ext4、ext4dev、f2fs、lvm、xfs、vfat和交换文件系统。

https://docs.ansible.com/ansible/latest/modules/filesystem_module.html

  • name: '扩展文件系统'
    filesystem:
    fstype: 'ext4'
    dev: '/dev/sda1'
    resizefs: yes
英文:

Don't know if this helps. But, since Ansible 2.0 there is resizefs option in the filesystem module that is false by default and that supports ext4.

If yes, if the block device and filesystem size differ, grow the filesystem into the space. Supported for ext2, ext3, ext4, ext4dev, f2fs, lvm, xfs, vfat, swap filesystems.

https://docs.ansible.com/ansible/latest/modules/filesystem_module.html

- name: 'Extend the FS'
  filesystem:
    fstype: 'ext4'
    dev: '/dev/sda1'
    resizefs: yes

huangapple
  • 本文由 发表于 2023年8月9日 18:12:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76866744.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定