Register being set even though task is skipped

653 views
Skip to first unread message

PePe Amengual

unread,
Jun 24, 2014, 4:12:55 PM6/24/14
to ansible...@googlegroups.com
Hi there
 
 I'm running into an issue that I don't know if it is a expected behaviour or a bug....
 I have a play with two task both of them have the conditional "when" and both of them use the same variable name as a register like so :


- name: Forcing Termination of instances
  hosts: localhost
  connection: local
  tasks:

    - name: Finding instances to terminate base on Build Number
      #shell: aws ec2 --output=json --region eu-west-1 describe-instances|jq '.Reservations[].Instances[] | select(contains({Tags':' [{Key':' "terminate_me"}]}))'|jq -r ".InstanceId"
      shell: aws ec2 --output=json --region eu-west-1 describe-instances --filter "Name=tag:jenkins_build,Values={{ jenkins_build }}" "Name=instance-state-name,Values=running"|jq -r ".Reservations[].Instances[].InstanceId"
      register: ec2_instancesIDs
      when: with_jenkins_build

    - name: Finding instances to terminate after Failed job run
      #shell: aws ec2 --output=json --region eu-west-1 describe-instances|jq '.Reservations[].Instances[] | select(contains({Tags':' [{Key':' "terminate_me"}]}))'|jq -r ".InstanceId"
      shell: aws ec2 --output=json --region eu-west-1 describe-instances --filter "Name=tag:terminate_me,Values=true" "Name=instance-state-name,Values=running"|jq -r ".Reservations[].Instances[].InstanceId"
      register: ec2_instancesIDs
      when: no_build_number

    - debug: var=ec2_instancesIDs

 I noticed in debug mode that even if the task is being skipped the variable is being set anyway so if I run the cleanup jenkins job and I use the jenkins build number and I call ansible like so :

 ansible-playbook -vvvv --tags cleanup --extra-vars no_build_number=false cleanup=true with_jenkins_build=true jenkins_build=70 jmeter/loadtools/site.yml

The ec2_instancesIDs value ends to be :

TASK: [debug var=ec2_instancesIDs] ******************************************** 
ok: [localhost] => {
    "ec2_instancesIDs": {
        "changed": false, 
        "skipped": true
    }
}

Because the last task is being skipped.

is this a expected behaviour ?

Thanks.

James Cammarata

unread,
Jun 24, 2014, 6:58:00 PM6/24/14
to ansible...@googlegroups.com

Yes this is expected. Register always stores the state of the task, but you can just check the .skipped value in your when: statement.

--
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/445e4ea3-e7be-4af1-90ca-5bf2900c425f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages