我创建了一个test_cred秘密文本类型的凭证来存储密码,该密码应该传递给 ansible 剧本。我将此参数作为额外变量传递root_pass给 ansible,但该值root_pass被评估为字符串test_cred而不是其中包含的秘密文本。有人可以帮助获取凭证的值,test_cred以便我可以将其传递给 ansible。
stages {
stage('Execution') {
steps {
withCredentials([string(credentialsId: 'test_cred', variable: 'test')]) {
}
ansiblePlaybook(
installation: 'ansible',
inventory: "inventory/hosts",
playbook: "${PLAYBOOK}",
extraVars: [
server: "${params.Server}",
client: "${params.Client}",
root_pass: "${test}"
]
)
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个文件,file内容如下:
stringa 8.0.1.2 stringx
stringb 12.01.0.0 stringx
Run Code Online (Sandbox Code Playgroud)
我必须从字段 2 中获取子字符串(前两个带点的值)。我目前正在做cat file | awk '{print $2}' | awk -F. '{print $1"."$2}'并得到预期的输出:
8.0
12.01
Run Code Online (Sandbox Code Playgroud)
我怎样才能用一个 AWK 来做到这一点?
我尝试过使用 match(),但我没有看到向后引用的选项。
dir_lst_raw我在 ansible playbook 中有一个变量,其值是一个列表,如下所示:
"dir_lst_raw": [
"/path1/dir1/user",
"/path2/dir2/admin",
"/path3/dir3/user.ansible_backup_2020-03-16",
"/path1/dir1/config.ansible_backup_2020-03-16",
"/path2/dir2/dir3/somefile"
]
Run Code Online (Sandbox Code Playgroud)
我需要删除包含的所有行并将其作为列表.ansible_backup_保存到另一个变量中。我在谷歌上搜索了正则表达式,并尝试将模式与选择过滤器不匹配,如下所示:
- set_fact:
dir_lst: "{{ dir_lst_flt_r | select('match','(^.ansible_backup_)+') | list }}"
Run Code Online (Sandbox Code Playgroud)
但新变量dir_lst结果是一个空列表。我期待dir_lst如下:
"dir_lst_raw": [
"/path1/dir1/user",
"/path2/dir2/admin",
"/path2/dir2/dir3/somefile"
]
Run Code Online (Sandbox Code Playgroud)
有人可以建议我怎样才能完成它吗?