无法使用正则表达式或在可执行任务上搜索字符串搜索



团队,

我在下面有一个任务,我想在那里创建一个条件,并在此基础上运行其他任务。因此,作为第一步,创建条件任务本身是失败的,因为我无法弄清楚语法。。运行了几次迭代,并在此处在线查看https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html

任何提示,我都是新手。

- name: Identify device naming convention[nvme*] using REGEX
debug:
msg: "Found Block Device {{ item.0.device }}"
loop:  "{{ local_volume_mount_disks|subelements('partitions') }}"
#when: "{{ item.0.device }}" is regex("nvme2w+"). #<<<FAILED
when: "{{ item.0.device }}" is search("nvme")
register: nv_device_type
tags: tag_to_create_with_values, tag_to_delete
- name: Output device from REGEX results
debug:
var: nv_device_type
ignore_errors: no

输出

ERROR! Syntax Error while loading YAML.
expected <block end>, but found '<scalar>'

The error appears to be in '/ansible-managed/jenkins-slave/slave0/workspace/nvdc/run_ansible_playbook@2/k8s/baremetal/roles/local_volume_mount/tasks/main.yml': line 45, column 33, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

#when: "{{ item.0.device }}" is regex("nvme2w+")
when: "{{ item.0.device }}" is search("nvme")
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:

with_items:
- {{ foo }}

Should be written as:

with_items:
- "{{ foo }}"

我的数值低于

local_volume_mount_disks:
- device: /dev/nvme2n1
partitions:
- number: 1

经过几次迭代后才发现。。

- name: Identify device naming convention[nvme*] using REGEX
debug:
msg: "Found Block Device {{ item.0.device }}"
loop:  "{{ local_volume_mount_disks|subelements('partitions') }}"
when: '"{{item.0.device }}" is search("nvme")'
register: nv_device_type

输出

ok: [node1] => (item=[{'device': '/dev/nvmedn1', 'partitions': [{'number': 1, 'start': '0%', 'end': '100%'}]}, {'number': 1, 'start': '0%', 'end': '100%'}]) => {
"msg": "Found Block Device /dev/nvmedn1"
}

相关内容

  • 没有找到相关文章

最新更新