Ansible 2.2向后兼容

时间:2016-11-04 13:36:21

标签: ansible ansible-2.x

尝试在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"
}

1 个答案:

答案 0 :(得分:2)

cannot use bare variables了:

with_items: ec2_agent2_agent.instances

应该是:

with_items: "{{ ec2_agent2_agent.instances }}"