DigitalOcean Ansible 视图注册变量

DigitalOcean Ansible view registered variable

我正在尝试使用 Ansible 抛出 DigitalOcean 水滴。这应该让我拥有一切美好的基础设施即代码。我已经尝试过动态库存插件,但它并不是我现在所追求的。

- name: Add droplet
  digital_ocean: >
    state=present
    command=droplet
    name={{ item.key }}
    size_id=512mb
    region_id=ams2
    image_id={{ item.value.image_id }}
    ssh_key_ids={{ my_ssh_key.ssh_key.id }}
    unique_name=yes
  with_dict: "{{ droplets_up }}"
  register: my_droplet

- debug: msg="Droplet ID is {{ my_droplet.droplet.id }}"

不要担心所有变量 - 液滴按预期出现,但是,调试步骤失败:

fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'dict object' has no attribute 'droplet'\n\nThe error appears to have been in '/Users/jerry/free_code/d-ocean/ansible/roles/dropletctl/tasks/main.yml': line 23, 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- debug: msg=\"Droplet ID is {{ my_droplet.droplet.id }}\"\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo }}\"\n"}

但是,如果我 运行 在详细模式下播放,我可以看到该变量应该存在。 Ansible 模块文档页面上使用了一个非常类似的示例,所以我认为它应该可以工作。

只是为了关闭这个,"drill down"进入调试输出的详细输出的方法如下:

- name: Print droplets variable
  debug:
    msg: "{{ my_droplet.results | map(attribute='droplet.<variable you'd like to print>') | list }}"

..例如在哪里ip_address