# Register being set even though task is skipped

**URL:** <https://forum.ansible.com/t/register-being-set-even-though-task-is-skipped/15538>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [June 24, 2014, 8:12pm UTC](https://forum.ansible.com/t/register-being-set-even-though-task-is-skipped/15538 "2014-06-24T20:12:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PePe\_Amengual](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@PePe\_Amengual](https://forum.ansible.com/u/PePe_Amengual)\
**Post date:** [June 24, 2014, 8:12pm UTC](https://forum.ansible.com/t/register-being-set-even-though-task-is-skipped/15538/1 "2014-06-24T20:12:55Z")

</div>

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 :

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [June 24, 2014, 10:57pm UTC](https://forum.ansible.com/t/register-being-set-even-though-task-is-skipped/15538/2 "2014-06-24T22:57:50Z")

</div>

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