【发布时间】:2022-01-20 07:36:19
【问题描述】:
我正在尝试编写一个 ansible 任务以将以下命令的输出合并到 /etc/lvm/lvm.conf 文件中:
[root@ansible]# vgs --noheadings -o vg_name
my_vg
rhel_home
rhel_root
上面提到的值需要添加如下:
volume_list = [ "rhel_root", "rhel_home", "my_vg" ]
在被管节点中,上述参数如下:
# volume_list = [ "vg1", "vg2/lvol1", "@tag1", "@*" ]
由于我被困在这里,请帮助我继续前进:
- name: Fetch the Volume group
shell: "vgs --noheadings -o vg_name"
register: vgs
- debug:
msg: "{{ vgs.stdout }}"
- name: Line in file
lineinfile:
path: /tmp/lvm.conf
regex: "volume_list = .*"
line: "volume_list = [ vgs.stdout_lines ]"
它正在添加如下一行,vg 名称中没有双引号: volume_list = [ vgs.stdout_lines ] 在底部而不是替换以下行:
volume_list = [ "vg1", "vg2/lvol1", "@tag1", "@*" ]
需要帮助才能获得输出为 volume_list = [ "rhel_root", "rhel_home", "my_vg" ]
【问题讨论】:
-
您应该查看
vgs.stdout_lines,因为这是命令返回的 VG 名称列表。 -
我尝试了以下任务:``` - name: Line in file lineinfile: path: /tmp/lvm.conf regex: "# volume_list = .*" line: "\tvolume_list = [ \" vgs.stdout_lines\" ]" ``` 但没有运气