我有一个 Yaml 格式的文件(如下所述)。
值.yml
replicaCount: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
nodeSelector:
role: nginxplus
image:
repository: 2xxxxxxxxxxx6.dkr.ecr.us-east-1.amazonaws.com/miqp-devops
tag: foo
pullPolicy: IfNotPresent
现在我想用另一个值替换键标签。该值来自变量。
例如,
VAR=bar
echo $VAR
bar
我想要一些可以编辑我的values.yml 文件并替换的东西
标签:foo 到标签:bar
谢谢
最佳答案
sed方法:
var="bar"
sed -i "s/^\([[:space:]]*tag:[[:space:]]*\).*/\1$var/" values.yml
最终的values.yml
内容:
replicaCount: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
nodeSelector:
role: nginxplus
image:
repository: 2xxxxxxxxxxx6.dkr.ecr.us-east-1.amazonaws.com/miqp-devops
tag: bar
pullPolicy: IfNotPresent
关于linux - 在 YAML 文件中的特定字符串之后传递变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46645448/