【问题标题】:Ansible module amazon.aws and the aws_service_ip_ranges lookup pluginAnsible 模块 amazon.aws 和 aws_service_ip_ranges 查找插件
【发布时间】:2021-11-02 15:02:03
【问题描述】:

在测试 Cloudfront WAF 实例时,我需要 Cloudfront 用于我们的实例的 IP 列表或 IP 范围,以便我们可以在防火墙中将它们列入白名单。看来 Ansible 模块集合 amazon.aws 和查找插件 aws_service_ip_ranges 可以做到这一点,但是我非常坚持在 yaml 中获取正确的语法。

我已经阅读了docshereherehere,但我仍然不太明白如何成功查找使用的 IP。我需要一个具体的例子来说明如何编写 yaml 来获取这些 IP。使用文档中给出的示例并没有奏效,我再次不清楚这些示例的语法。

这是我现在所拥有的,它在 vars: 行返回语法错误。

---
- hosts: <hostname>
  remote_user: ansible
  collections: amazon.aws
  tasks:
  - name:  Get IP Range
    plugin: aws_service_ip_ranges
      vars:
       cloudfront_ranges: "{{ lookup('aws_service_ip_ranges', region 'us-east-1', service 'CLOUDFRONT', wantlist True) }}"
  - name: "use list return option and iterate as a loop"
    debug: msg="{% for cidr in cloudfront_ranges %}{{ cidr }} {% endfor %}"

【问题讨论】:

    标签: ansible yaml syntax-error


    【解决方案1】:

    答案是更简单,在剧本中做的更少。我将collectionsplugins 项目合二为一。将vars 移动到与collections 相同的选项卡级别。

    ---
    - hosts: <hostname>
      collections: 
       - amazon.aws.aws_service_ip_ranges
      remote_user: ansible
      vars: 
        cloudfront_ranges: "{{ lookup('aws_service_ip_ranges', service='CLOUDFRONT', wantlist=True) }}"
      tasks:
      - name: use list return option and iterate as a loop
        debug: msg="{% for cidr in cloudfront_ranges %}{{ cidr }} {% endfor %}"
    

    【讨论】:

    • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多