簡體   English   中英

使用 lineinfile ansible 模塊從正則表達式變量的單詞中排除字符串?

[英]Exclude a string from a word that's a variable with regex using lineinfile ansible module?

我有一個使用lineinfile模塊的 ansible 劇本。

它使用變量{{ inventory_hostname }}來表示line:任務的一部分

清單中的所有主機都有不同的名稱,但每個主機名的名稱都以這個.super.vms (不要問為什么,它必須是這樣的)所以它看起來像這樣:

[webservers]
server1.super.vms
server2.super.vms
database1.super.vms

...

現在我想添加到line: '{{ inventory_hostname }}'一些東西,所以它附加了沒有.super.vms的行,所以文件看起來像這樣:

server1
server2
database1

...

或者也許創建 lineinfile 將使用的另一個變量。

沒關系,我發現inventory_hostname_short變量由於某種原因排除了最后一部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM