开发者社区您好!
这是我在这里的第一篇文章 :-) 我对 Ansible 比较陌生,希望获得以下方面的帮助。我正在尝试创建一些脚本来管理 Citrix NetScaler VPX 上的功能。在这种特定情况下,我想部署一个包含已定义 SSL 密码的 SSL 密码组。我在 YAML 文件中定义了以下数据结构:
nsapp_sslciphergroup:
- ciphergroupname: "TEST_1"
sslcipher:
- ciphername: "TLS1.3-AES256-GCM-SHA384"
cipherpriority: "1"
- ciphername: "TLS1.3-CHACHA20-POLY1305-SHA256"
cipherpriority: "2"
- ciphername: "TLS1.3-AES128-GCM-SHA256"
cipherpriority: "3"
- ciphergroupname: "TEST_2"
sslcipher:
- ciphername: "TLS1.2-ECDHE-RSA-AES256-GCM-SHA384"
cipherpriority: "1"
- ciphername: "TLS1.2-ECDHE-RSA-AES128-GCM-SHA256"
cipherpriority: "2"
- ciphername: "TLS1.2-ECDHE-ECDSA-AES256-GCM-SHA384"
cipherpriority: "3"
这样的 NetScaler 不允许再次将相同的密码绑定到给定的密码组中,因此在进行任何更改之前,我需要以某种方式检查密码组及其绑定是否已经存在。所以第一次运行是可以的,但是任何连续的运行都会失败,因为给定的密码名已经绑定到密码组。当前代码如下:
- name: "Add SSL ciphergroup binding(s)"
netscaler_nitro_request:
<<: *nitro_login
operation: add
resource: sslcipher_sslciphersuite_binding
name: ""
attributes:
ciphergroupname: "{{ item.0.ciphergroupname }}"
ciphername: "{{ item.1.ciphername }}"
cipherpriority: "{{ item.1.cipherpriority }}"
register: add_sslcipher_sslciphersuite_binding_result
with_subelements:
- "{{ nsapp_sslciphergroup }}"
- "sslcipher"
- skip_missing: true
为了在再次运行脚本之前检查当前配置是什么,我有以下代码:
- name: "Check if SSL ciphergroup binding(s) are already defined"
netscaler_nitro_request:
<<: *nitro_login
operation: get
resource: sslcipher_sslciphersuite_binding
name: "{{ item.ciphergroupname }}"
attributes:
ciphergroupname: "{{ item.ciphergroupname }}"
register: get_sslcipher_sslciphersuite_binding_result
with_items: "{{ nsapp_sslciphergroup }}"
如果密码组已使用其绑定定义(并且对于“TEST_2”组也具有类似的输出,也具有各自的绑定),则此代码会产生以下结果(在“get_sslcipher_sslciphersuite_binding_result”变量中注册):
"nitro_object": [
{
"ciphergroupname": "TEST_1",
"ciphername": "TLS1.3-AES256-GCM-SHA384",
"cipherpriority": "1",
"description": "TLSv1.3 Kx=any Au=any Enc=AES-GCM(256) Mac=AEAD HexCode=0x1302",
"peflags": "4",
"stateflag": "512"
},
{
"ciphergroupname": "TEST_1",
"ciphername": "TLS1.3-CHACHA20-POLY1305-SHA256",
"cipherpriority": "2",
"description": "TLSv1.3 Kx=any Au=any Enc=CHACHA20/POLY1305(256) Mac=AEAD HexCode=0x1303",
"peflags": "4",
"stateflag": "512"
},
{
"ciphergroupname": "TEST_1",
"ciphername": "TLS1.3-AES128-GCM-SHA256",
"cipherpriority": "3",
"description": "TLSv1.3 Kx=any Au=any Enc=AES-GCM(128) Mac=AEAD HexCode=0x1301",
"peflags": "4",
"stateflag": "512"
}
],
我正在尝试在“with_subelements”部分之后添加一个“when”子句,但脚本的 add 部分总是想要运行。
有人可以建议检查“get_sslcipher_sslciphersuite_binding_result”变量是否包含给定密码组的给定密码名的正确方法是什么?
提前谢谢了!