微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我可以对多个值进行 grep

如何解决我可以对多个值进行 grep

可以对多个值进行 grep 吗? 我读取了一个 CSV 文件,其中包含 mac 和名称地址列表,但没有 VM id(我可以使用命令 qm list | sed '1d' | awk '{print $1,$2}' 获取)。 我想获取它并将其与正确的 MAC 地址相关联(名称在两个列表中是公共的)。

我试过了:

    - name: Read CSV file
    read_csv:
      path: names.csv
    register: listNames
    delegate_to: localhost 

   - name: Concatenate
     set_fact:
       my_joined_list: "{{ listNames.list | join('\n') }}"
   - name: Debug my_joined_list
     debug:
       msg: '"{{ my_joined_list }}"'

   - name: Add OR condition
     shell:  "{{ listNames.list }} | sed 's/'\n'/'|'/'"
     args:
       warn: no
     register: list1

    - name: Get all VMs IDs and names
     shell:  qm list | sed '1d' | awk '{print $1,$2}' | grep list1
     args:
       warn: no
     register: list2

   - name: Modify the VM mac address
     shell: "qm set {{ "IDItem" }} --net0 virtio='{{ item.mac_address }}',bridge='vmbr0',firewall=1"
     with_items:
       - "{{ list2 }}"
       - "{{ listNames.list.macAddress }}"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。