# Need help with deprecation warnings

**URL:** <https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425>\
**Category:** Ansible Project\
**Created:** [August 30, 2016, 7:36pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425 "2016-08-30T19:36:49Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayush.kumar](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@ayush.kumar](https://forum.ansible.com/u/ayush.kumar)\
**Post date:** [August 30, 2016, 7:36pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/1 "2016-08-30T19:36:49Z")

</div>

Hey all,

Just trying to figure out how to fix the deprecation warnings (recently updated to 2.1.1.0 from 1.7). I used to have the 4 individual tasks in the block below (I left the commented out when statements from the original 1.7 tasks). I tried refactoring a couple of times, but with the current setup, I still get “Skipping task due to undefined Error, in the future this will be a fatal error.: ‘project\_config’ is undefined.” on all 4 tasks when project\_config is undefined. Shouldn’t the block just skip the tasks? Is there something I’m missing about how blocks are executed? Is there a better way to rewrite this set of tasks?

- block:
- name: Install system dependencies for project  
become: True  
apt: pkg={{ item }} state=installed  
with\_items: " {{ project\_config.apt|default() }}"

# when: project\_config is defined and ‘apt’ in project\_config

- name: Install pip dependencies for project from files  
pip: requirements={{ full\_project\_root }}/project\_config/{{ item }}  
virtualenv\_command=virtualenv  
virtualenv={{ venvdir }}  
virtualenv\_python={{ venv\_python }}  
virtualenv\_site\_packages=no  
state=present  
with\_items: “{{ project\_config.pip\_files|default() }}”

# when: project\_config is defined and ‘pip\_files’ in project\_config

environment: “{{ pip\_internal }}”

- name: Install npm dependencies  
npm: path=“{{ full\_project\_root }}/project\_config/{{ item }}”  
state=latest  
production={{ npm\_production }}  
with\_items: “{{ project\_config.npm\_package\_json\_path|default() }}”

# when: project\_config is defined and ‘npm\_package\_json\_path’ in project\_config

- name: Run Django server setup commands  
django\_manage: command={{ item }}  
app\_path={{ django\_manage\_path }}  
virtualenv={{ venvdir }}  
settings={{ app\_module }}.settings.{{ env }}  
with\_items: “{{ project\_config.django\_commands|default() }}”

# when: project\_config is defined and ‘django\_commands’ in project\_config

when: project\_config is defined

Thanks.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 31, 2016, 2:45pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/2 "2016-08-31T14:45:04Z")

</div>

> Hey all,
> 
> Just trying to figure out how to fix the deprecation warnings (recently  
> updated to 2.1.1.0 from 1.7). I used to have the 4 individual tasks in the  
> block below (I left the commented out when statements from the original 1.7  
> tasks). I tried refactoring a couple of times, but with the current setup,  
> I still get "Skipping task due to undefined Error, in the future this will  
> be a fatal error.: 'project\_config' is undefined." on all 4 tasks when  
> project\_config is undefined. Shouldn't the block just skip the tasks?

You would think so, since the documentation says  
"...tasks will be executed after appending the when condition from the block and evaluating it in the task’s context."

> Is  
> there something I'm missing about how blocks are executed? Is there a  
> better way to rewrite this set of tasks?
> 
> - block:  
> &nbsp;&nbsp;&nbsp;&nbsp;- name: Install system dependencies for project  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become: True  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt: pkg={{ item }} state=installed  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: " {{ project\_config.apt|default() }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# when: project\_config is defined and 'apt' in project\_config

If project\_config is not defined this will work  
&nbsp;&nbsp;&nbsp;with\_items: "{{ project\_config | default() }}"

but thees two will give a deprecation warning  
&nbsp;&nbsp;&nbsp;with\_items: "{{ project\_config.apt | default() }}"  
&nbsp;&nbsp;&nbsp;with\_items: "{{ project\_config['apt'] | default() }}"

To me this looks like a bug.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 10, 2016, 8:18am UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/3 "2016-09-10T08:18:54Z")

</div>

> > Is  
> > there something I'm missing about how blocks are executed? Is there a  
> > better way to rewrite this set of tasks?
> > 
> > - block:  
> > &nbsp;&nbsp;&nbsp;&nbsp;- name: Install system dependencies for project  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become: True  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt: pkg={{ item }} state=installed  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: " {{ project\_config.apt|default() }}"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# when: project\_config is defined and 'apt' in project\_config

This will work.  
First project\_config need to be filtered through default, and then project\_config.apt.

&nbsp;&nbsp;&nbsp;with\_items: " {{ (project\_config | default()).apt | default() }}"

> If project\_config is not defined this will work  
> &nbsp;&nbsp;with\_items: "{{ project\_config | default() }}"
> 
> but thees two will give a deprecation warning  
> &nbsp;&nbsp;with\_items: "{{ project\_config.apt | default() }}"  
> &nbsp;&nbsp;with\_items: "{{ project\_config['apt'] | default() }}"
> 
> To me this looks like a bug.

This is not a bug, please disregards my statement.

---

<div class="post-metadata">

**Author:** ![ayush.kumar](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@ayush.kumar](https://forum.ansible.com/u/ayush.kumar)\
**Post date:** [September 13, 2016, 10:30am UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/4 "2016-09-13T10:30:35Z")

</div>

Thanks for the sleuthing.

It seems like using a “is-defined” check as a conditional is pointless if we have to send everything through default anyway. I understand the change for loops (since it checks each item now), but this behavior seems really counter-intuitive for blocks. What’s even the point of grouping it into a block if I have to set those default filters on each task? It’s just going back to being 4 separate tasks.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [September 13, 2016, 5:26pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/5 "2016-09-13T17:26:06Z")

</div>

blocks let you do 2 things, handle errors and ‘share settings’, the conditional does not affect the block itself, it is a way to allow all tasks to inherit it, instead of writing it N times.

---

<div class="post-metadata">

**Author:** ![Ralph\_Bolton](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@Ralph\_Bolton](https://forum.ansible.com/u/Ralph_Bolton)\
**Post date:** [November 15, 2016, 12:20pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/6 "2016-11-15T12:20:18Z")

</div>

I’ve been bitten by this too. In my case I had this:

- name: Create plain FTP groups  
group: name={{ item.user }} gid={{ item.uid }} state={{ item.state|default(‘present’) }}  
with\_items: “{{ customer\_ftp\_accounts[inventory\_hostname] }}”

when: inventory\_hostname in customer\_ftp\_account

I got this error:

TASK [customer\_sftp : Create plain FTP groups] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error.: ‘dict object’ has no attribute u’internal’.  
This feature will be removed in a future release. Deprecation warnings can be disabled by setting  
deprecation\_warnings=False in ansible.cfg.  
skipping: [myserver]

It threw me off because it’s purple and says “DEPRECATION WARNING”, but it’s just a regular error really. It does what I want, in so much as it skips hosts not in a particular list, but I could do without the error. It’s of course fixed like this:

- name: Create plain FTP groups  
group: name={{ item.user }} gid={{ item.uid }} state={{ item.state|default(‘present’) }}  
with\_items: “{{ customer\_ftp\_accounts[inventory\_hostname]|default() }}”

I’ve put a comment in the file which describes it like this:

If using “with\_items”, the “when” is evaluated on each iteration of the loop, and not when looking at the task as a whole. As such, trying to ‘lock out’ the task with a “when” won’t work, and instead we have to default the “with\_items” with an empty list if we don’t want to run the loop at all.

Taking a ‘step back’ from this, it makes sense for Ansible to work this way, but it can easily catch you out as a single task (with no “with\_items”) works in a way you may mentally extrapolate out to loops.

…Ralph

---

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [February 28, 2017, 4:44pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/7 "2017-02-28T16:44:37Z")

</div>

This does not remove the deprecation warning for me in 2.1.2.0

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 28, 2017, 5:02pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/8 "2017-02-28T17:02:48Z")

</div>

It does, if it doesn't work for you, you should show us your code so we can help.

---

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [February 28, 2017, 5:12pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/9 "2017-02-28T17:12:18Z")

</div>

Sorry, I was wrong. This does indeed remove the warning.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 28, 2017, 6:06pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/10 "2017-02-28T18:06:35Z")

</div>

note the change, only the last one is an empty list , if  
project\_config is undefined it should be an empty hash/dictionary, as  
.apt can only be part of that and not a list. Default will need to  
return what is expected of the 'next step'

with\_items: " {{ (project\_config | default({})).apt | default() }}"

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 28, 2017, 6:35pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/11 "2017-02-28T18:35:22Z")

</div>

My experience is that it doesn't matter it I use {}, or a mix, it works either way.

&nbsp;&nbsp;&nbsp;- name: " "  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug: msg="This will not print {{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: " {{ (project\_config | default()).apt | default() }}"

&nbsp;&nbsp;&nbsp;- name: "{} "  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug: msg="This will not print {{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: " {{ (project\_config | default({})).apt | default() }}"

&nbsp;&nbsp;&nbsp;- name: " {}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug: msg="This will not print {{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: " {{ (project\_config | default()).apt | default({}) }}"

&nbsp;&nbsp;&nbsp;- name: "{} {}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug: msg="This will not print {{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: " {{ (project\_config | default({})).apt | default({}) }}"

TASK [] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [{}] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [{}] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [{} {}] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=0 changed=0 unreachable=0 failed=0

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 28, 2017, 6:38pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/12 "2017-02-28T18:38:17Z")

</div>

As long as project\_config is defined, if not you'll get an attribute  
error exception

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 28, 2017, 6:48pm UTC](https://forum.ansible.com/t/need-help-with-deprecation-warnings/22425/13 "2017-02-28T18:48:30Z")

</div>

I don't get any errors, here is the full playbook.
