【问题标题】:ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'private_ip'ansible.vars.unsafe_proxy.AnsibleUnsafeText 对象'没有属性'private_ip'
【发布时间】:2018-02-04 08:45:57
【问题描述】:

发件人:Best way to launch aws ec2 instances with ansible

  - name: Add the newly created EC2 instance(s) to the local host group (located inside the directory)
    local_action: lineinfile 
                  dest="/etc/ansibles/aws/hosts" 
                  regexp={{ item.private_ip }} 
                  insertafter="[webserver]" line={{ item.private_ip }}
    with_items: "{{ ec2.instances }}"

产生这个错误:

致命:[本地主机]:失败! => { “失败”:真的, "msg": "字段 'args' 的值无效,似乎包含一个未定义的变量。错误是:'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'private_ip'\n\n

我已经定义了变量 private_ip: 在 vars 下,有一个值

【问题讨论】:

    标签: amazon-web-services amazon-ec2 ansible boto


    【解决方案1】:

    我认为上面代码中的 private_ip 属性引用了 ec2 变量的属性,该属性用于从 ec2 模块(从最后一步)捕获返回值,而不是您在其他地方定义的那个。

      - name: Launch the new EC2 Instance
        local_action: ec2 
                      group={{ security_group }} 
                      instance_type={{ instance_type}} 
                      image={{ image }} 
                      wait=true 
                      region={{ region }} 
                      keypair={{ keypair }}
                      count={{count}}
        register: ec2 (this is where the variable is defined!!!)
    

    本质上 Ansible 抱怨 ec2 变量没有得到 ​​p>

    属性'private_ip'

    ,所以检查前面的代码,看看这个变量是如何定义的。

    在上面的示例中,您尝试从 aws 获取 private_ip 地址。这真的是你想要的吗?大多数情况下,您需要公共 IP 地址,因为您将使用它来连接到 ec2 机器、配置它、部署您的应用程序等......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 2021-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多