Re: [ansible-project] skipped role attempts to execute tasks based on tags

24 views
Skip to first unread message

Michael DeHaan

unread,
Oct 20, 2014, 5:08:58 PM10/20/14
to ansible...@googlegroups.com
Can you please show where elb is set?


On Thu, Oct 16, 2014 at 5:06 PM, Matthew Morgan <hex...@gmail.com> wrote:
Not sure if I'm doing this wrong or not, so I figured I'd ask.

I have a playbook to apply a role, but the role has a conditional.  If the conditional evaluates to false, the role should be skipped.
# service.yml
---
- name: Create EC2 Instances
  gather_facts: False
  hosts: local
  vars_files:
    - vars/defaults.yml
    - vars/{{deploy_env}}.yml
    - vars/{{region}}.yml
    - vars/{{service}}.yml
  roles:
    - ec2-box
    - { role: ec2-elb, when: elb }


In this case elb is set to false, so all the tasks in the ec2-elb role should be skipped.

However, I also run the playbook using tags.  

ansible-playbook -vvvv -i hosts service.yml --tags configure,start -e service=myservice

And all of the tasks in ec2-elb have tags assigned:

# roles/ec2-elb/tasks/main.yml
---
- name: Create ELB
  local_action:
    module: ec2_elb_lb
    name: "{{deploy_env}}-{{service}}"
    state: present
    cross_az_load_balancing: yes
    security_group_ids: "{{sg_ids}}"
    region: "{{region}}"
    subnets:
      - {{public_vpc_subnet_a}}
      - {{public_vpc_subnet_a}}
      - {{public_vpc_subnet_a}}
    listeners:
      - protocol: https
        load_balancer_port: 443
        instance_protocol: http
        instance_port: "{{service_port}}"
        ssl_certificate_id: "{{ssl_cert_arn}}"
    health_check:
        ping_protocol: http
        ping_port: 6990
        ping_path: "/1.0/status"
        response_timeout: 5
        interval: 10
        unhealthy_threshold: 2
        healthy_threshold: 2
  register: elb
  tags:
    - configure
    - start
    - stop
    - restart

- name: Wait Until ELB Responds
  local_action:
    module: wait_for 
    host: "{{elb.elb.dns_name}}" 
    port: 443 
    timeout: 300
  tags:
    - start
    - configure
    - restart


Given this approach, I would expect that if elb evalutates to False or undefined, the ec2-elb role would be skipped.

Unfortunately, It seems the tasks within the ec2-elb role still attempt to execute based off the tags:

TASK: [ec2-elb | Create ELB] ************************************************** 
skipping: [localhost -> 127.0.0.1]

TASK: [ec2-elb | Wait Until ELB Responds] ************************************* 
fatal: [localhost -> 127.0.0.1] => error while evaluating conditional: {u'skipped': True, u'changed': False}

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/mmorgan/service.retry

localhost                  : ok=5    changed=1    unreachable=1    failed=0   

Am I doing something wrong here, or is this a bug?

Thanks!


--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9817e427-0d4d-4732-9e1f-0022396d41a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages