【问题标题】:Ansible 2.2 backward compatibility [duplicate]Ansible 2.2向后兼容性[重复]
【发布时间】:2016-11-04 13:36:20
【问题描述】:

尝试在 ec2 上配置新实例

在 ansible 2.1 上工作正常,在 ansible 2.2 上失败 (见下面的错误)

  - name: Provision Windows 2012
    local_action:
      module: ec2
      key_name: "{{key_name}}"
      region: "{{aws_region}}"
      group_id: [ "{{basic_firewall.group_id}}" , sg-123456 ]
      instance_type: t2.small
      image: "{{ami_2012r2}}"
      vpc_subnet_id: "{{vpc_subnet_id}}"
      count: 1
      wait: no
      instance_tags: '{"Name":"2012r2-DSM-Agent-{{TAG}}-{{BuildNumber}}","Role":"Agent2","Build":"{{BuildNumber}}","Owner":"{{Owner}}","Test":"1.Pair.UB.backup.restore"}'
    register: ec2_agent2_agent
  - name: debug instance start
    debug: 'msg="{{ ec2_agent2_agent}}"'
  - name: add newly provisioned servers to a group 2012r2_agent
    local_action: add_host 
                  hostname={{item.private_ip}} 
                  groupname=agent2,agents,windows,all_windows
                  TAG={{TAG}} 
                  ProductVersion={{ProductVersion}} 
                  BuildNumber={{BuildNumber}} 
                  Owner={{Owner}} 
                  RunTests={{RunTests}} 
                  Name=agent2
                  IP={{item.private_ip}}
    with_items: ec2_agent2_agent.instances

输出:

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: 'unicode object' has no attribute 'private_ip'\n\nThe error appears to have been in '/opt/SVN/trunk/testing/environments/EC2.DSM.1.Pair.Backup.Restore.UB.test.yml': line 136, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n    register: ec2_ubuntu_dsm\n  - name: add newly provisioned servers to a group ubuntu_dsm\n    ^ here\n"
}

【问题讨论】:

  • 自 Ansible 2.0 以来,您应该已经收到有关此问题的警告。

标签: ansible ansible-2.x


【解决方案1】:

cannot use bare variables了:

with_items: ec2_agent2_agent.instances

应该是:

with_items: "{{ ec2_agent2_agent.instances }}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多