问题描述
可以对多个值进行 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 (将#修改为@)