Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 如何在ansible(jinja2)中更改字典中的嵌套变量_Variables_Ansible_Jinja2_Ansible Template - Fatal编程技术网

Variables 如何在ansible(jinja2)中更改字典中的嵌套变量

Variables 如何在ansible(jinja2)中更改字典中的嵌套变量,variables,ansible,jinja2,ansible-template,Variables,Ansible,Jinja2,Ansible Template,我目前正在尝试使用ansible的acme_证书模块为我的服务器自动生成一个lets加密证书。由于我的服务提供商没有提供与route53兼容的端点,我不得不编写自己的python脚本来上传DNS记录,包括质询。因此,我需要将质询数据(特定于质询字符串本身)传递给python脚本,我不知道如何在字典中嵌套变量以访问正确的元素。有没有办法解决这个问题(我尝试过使用查找,但最终出现了更多的错误) 我的剧本: --- - hosts: localhost vars: dns_name: sa

我目前正在尝试使用ansible的acme_证书模块为我的服务器自动生成一个lets加密证书。由于我的服务提供商没有提供与route53兼容的端点,我不得不编写自己的python脚本来上传DNS记录,包括质询。因此,我需要将质询数据(特定于质询字符串本身)传递给python脚本,我不知道如何在字典中嵌套变量以访问正确的元素。有没有办法解决这个问题(我尝试过使用查找,但最终出现了更多的错误)

我的剧本:

---
- hosts: localhost
  vars:
    dns_name: sample.com

tasks:
- name: submit request
  acme_certificate:
    account_key_src: "{{ tmpdir }}{{ account_key }}"
    account_email: cert@{{ dns_name }}
    src: "{{ tmpdir }}{{ csrname }}"
    fullchain_dest: "{{ tmpdir }}{{ certname }}"
    challenge: dns-01
    acme_directory: https://acme-staging-v02.api.letsencrypt.org/directory
    acme_version: 2
    terms_agreed: yes
    remaining_days: 60
  register: challenge

- name: publish challenge as TXT record
  shell: "python3 /tmp/publish_dns.py --dns_name {{ dns_name }} {{ challenge.challenge_data['*.{{ dns_name }}']['dns-01'].resource_value }}"
运行playbook时,出现以下错误:

TASK [deploy_phishing : publish challenge as TXT record] 
***********************
fatal: [server1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute '*.{{ dns_name }}'\n\nThe error appears to be in '/var/lib/awx/projects/test/roles/generat_cert/tasks/tasks1.yml': line 76, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: publish challenge as TXT record\n  ^ here\n"}

昨天我回答了一个几乎相同的问题:我尝试使用your question中建议的查找功能,我的解决方案如下:{{lookup('vars',challenge.challenge_data['.*.+dns_name+'']['dns-01'].resource_value)}但是我确实得到以下错误:任务[deploy_phishing:publish challenge as TXT record]************************致命:[ps1]:失败!=>{“msg”:"该任务包含一个带有未定义变量的选项。错误是:未找到具有此名称的变量:Huchabcdbcrhfumr_AjQxl_8XnSkzS6OEahwW_9FFw\n\n错误出现在“/var/lib/awx/projects/test/roles/deploy\u cert/tasks/tasks1.yml”:第76行第3列,但可能\n在文件的其他位置,具体取决于语法问题。\n\n行似乎是:\n\n\n-name:publish challenge as TXT record\n^here\n“}