I rewrote my playbooks like

  tasks:
    - { include: tasks/create.yml, items: '{{ nodes }}' }

---
- name: Launch instance
  local_action: ec2
    group={{ item.group | default(group) }}
    keypair={{ item.keypair | default(keypair) }}
    image={{ item.image | default(image) }}
    instance_type={{ item.instance_type | default(instance_type) }}
    instance_tags='{"Name":"{{ item.tags | default(item.user_data) | 
default(tags) }}"}'
    zone={{ zone }}
    region={{ region }}
    user_data={{ item.user_data | default(user_data) }}
    aws_access_key={{ aws_access_key }}
    aws_secret_key={{ aws_secret_key }}
    wait=true
  register: ec2
  with_items: items

- name: Send email to devops
  local_action: mail
    from=...
    to=...
    subject="EC2 instance {{ item.instances.0.public_ip }} - {{ 
item.instances.0.id }}"
    body="{{ item.instances.0 | to_nice_json }}"
  when: item.changed == true
  with_items: ec2.results

It fixed my problem.

I think will be very good add to documentation some examples like this. Can 
you do it?


пятница, 17 января 2014 г., 11:34:50 UTC+3 пользователь Alexander Petrovsky 
написал:
>
> Hello!
>
> Yesterday I've update my ansible from 1.3 to 1.5 and it's broke all my 
> playbooks.
>
> My playbooks looks like:
>
> *create.yml:*
> - name: Recreate instance
>   hosts: localhost
>   gather_facts: False
>   vars_files:
>     - vars/main.yml
>
>     - vars/staging.yml
>   tasks:
>     - include: tasks/create.yml
>       with_flattened:
>         - '{{ staging }}'
>
> *tasks/create.yml:*
> ---
> - name: Launch instance
>   local_action: ec2
>     group={{ item.group | default(group) }}
>     keypair={{ item.keypair | default(keypair) }}
>     image={{ item.image | default(image) }}
>     id={{ item.id | default(item.user_data) | default(user_data) }}
>     instance_type={{ item.instance_type | default(instance_type) }}
>     instance_tags='{"Name":"{{ item.tags | default(item.user_data) | 
> default(user_data) }}"}'
>     zone={{ zone }}
>     region={{ region }}
>     user_data={{ item.user_data | default(user_data) }}
>     aws_access_key={{ aws_access_key }}
>     aws_secret_key={{ aws_secret_key }}
>     wait=true
>   register: ec2
>
> - name: Send email to devops
>   local_action: mail
>     from=my_mail
>     to=my_mail
>     subject="EC2 instance {{ item.public_ip }} - {{ item.id }}"
>     body="{{ item | to_nice_json }}"
>   with_items: ec2.instances
>   when: ec2.changed == true
>
> - name: Add new instance to host group
>   local_action: add_host hostname={{ item.public_ip }} groupname=launched
>   with_items: ec2.instances
>   when: ec2.changed == true
>
>
> And right now, I dont' know how to rewrite my playbooks in proper way.
>
> When I move with_flattened into "Launch instance" in my include section:
>
> - name: Launch instance
>   local_action: ec2
>     group={{ item.group | default(group) }}
>     keypair={{ item.keypair | default(keypair) }}
>     image={{ item.image | default(image) }}
>     id={{ item.id | default(item.user_data) | default(user_data) }}
>     instance_type={{ item.instance_type | default(instance_type) }}
>     instance_tags='{"Name":"{{ item.tags | default(item.user_data) | 
> default(user_data) }}"}'
>     zone={{ zone }}
>     region={{ region }}
>     user_data={{ item.user_data | default(user_data) }}
>     aws_access_key={{ aws_access_key }}
>     aws_secret_key={{ aws_secret_key }}
>     wait=true
>   register: ec2
>   with_flattened:
>     - '{{ staging }}'
>
> The "Send email to devops" and "Add new instance to host group" sections 
> break.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to