Re: [ansible-project] yum module gives "AttributeError: 'list' object has no attribute 'strip'" on list of items

2019-03-28 Thread James Cassell


On Thu, Mar 28, 2019, at 7:57 AM, Roevens Robin wrote:
> Hi Sebastian
> Merging the lists indeed did the trick. Thanks for the suggestion!
> However, I have another, related question; The next task in this
> playbook is like this:
> - name: Install extra packages required for plugins  yum:  name:
> "{{ item.packages }}"  state: "present"  with_items:   - "{{
> default_plugins }}"  - "{{ plugins | d(omit) }}"  when:
> item.packages is defined
> And currently ansible even doesn't give a deprecation warning on this

In my opinion, the depreciation warning should have never been added, as your 
task will never stop working. It was more like a feature notification that you 
can install multiple packages at once, which ansible does sometimes 
automatically.  In your case here, ansible does not automatically install all 
the packages at once, so there's no warning that ansible will stop doing so in 
a future release.  In any case your playbook will continue to have the same end 
result as it does today, with our without changes to squash this warning.

V/r,
James Cassell


> task despite that I'm using a loop in combination with yum. And the
> only difference I see is that i'm using {{ item.packages }} instead of
> {{ item }} but I assume this will also deprecate ?How should I rewrite
> this then ?
> Thanks
> Robin
> Sebastian Meyer schreef op wo 27-03-2019 om 18:47 [+0100]:
> > Hi Robin,
> > 
> > On 27.03.19 17:16, Robin Roevens wrote:
> > > Hi all
> > > 
> > > I'm currently trying to get rid of all deprecation warnings as we
> > > upgraded 
> > > Ansible 2.3 to 2.7.9 (CentOS 7.4)
> > > And I have this code:
> > > 
> > > - name: Install required system packages
> > >   yum:
> > > name: "{{ item }}"
> > > state: 'present'
> > >   with_items:
> > > - "{{ base_packages }}"
> > > - "{{ additional_packages | d(omit) }}"
> > 
> > Assuming base_packages and additional_packages are lists, try:
> > 
> > - name: install pkgs
> >   yum:
> > state: present
> > name: "{{ base_pkgs + additional_pkgs | default([]) }}"
> > 
> > Ansible wants a flat list here. The suggestion in the deprecation
> > warning thinks both are just normal values and wants you to put them
> > into a list.
> > 
> > But if you already have lists, merge them with + as in the above
> > code.
> > 
> > HTH,
> > Sebastian
> > 
> > -- 
> > Sebastian Meyer
> > Linux Consultant & Trainer
> > Mail: me...@b1-systems.de
> > 
> > B1 Systems GmbH
> > Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
> > GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB
> > 3537
> > 
> -- 
> Dit bericht is gescanned op virussen en andere gevaarlijke
> inhoud door MailScanner en lijkt schoon te zijn.
> 
> -- 
> 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-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/1553774236.2809.132.camel%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1553774839.249222.1668783704.6402E373%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] yum module gives "AttributeError: 'list' object has no attribute 'strip'" on list of items

2019-03-28 Thread Roevens Robin
Hi Sebastian
Merging the lists indeed did the trick. Thanks for the suggestion!
However, I have another, related question; The next task in this
playbook is like this:
- name: Install extra packages required for plugins  yum:  name:
"{{ item.packages }}"  state: "present"  with_items:   - "{{
default_plugins }}"  - "{{ plugins | d(omit) }}"  when:
item.packages is defined
And currently ansible even doesn't give a deprecation warning on this
task despite that I'm using a loop in combination with yum. And the
only difference I see is that i'm using {{ item.packages }} instead of
{{ item }} but I assume this will also deprecate ?How should I rewrite
this then ?
Thanks
Robin
Sebastian Meyer schreef op wo 27-03-2019 om 18:47 [+0100]:
> Hi Robin,
> 
> On 27.03.19 17:16, Robin Roevens wrote:
> > Hi all
> > 
> > I'm currently trying to get rid of all deprecation warnings as we
> > upgraded 
> > Ansible 2.3 to 2.7.9 (CentOS 7.4)
> > And I have this code:
> > 
> > - name: Install required system packages
> >   yum:
> > name: "{{ item }}"
> > state: 'present'
> >   with_items:
> > - "{{ base_packages }}"
> > - "{{ additional_packages | d(omit) }}"
> 
> Assuming base_packages and additional_packages are lists, try:
> 
> - name: install pkgs
>   yum:
> state: present
> name: "{{ base_pkgs + additional_pkgs | default([]) }}"
> 
> Ansible wants a flat list here. The suggestion in the deprecation
> warning thinks both are just normal values and wants you to put them
> into a list.
> 
> But if you already have lists, merge them with + as in the above
> code.
> 
> HTH,
> Sebastian
> 
> -- 
> Sebastian Meyer
> Linux Consultant & Trainer
> Mail: me...@b1-systems.de
> 
> B1 Systems GmbH
> Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
> GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB
> 3537
> 
-- 
Dit bericht is gescanned op virussen en andere gevaarlijke
inhoud door MailScanner en lijkt schoon te zijn.

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1553774236.2809.132.camel%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] yum module gives "AttributeError: 'list' object has no attribute 'strip'" on list of items

2019-03-27 Thread Sebastian Meyer
Hi Robin,

On 27.03.19 17:16, Robin Roevens wrote:
> Hi all
> 
> I'm currently trying to get rid of all deprecation warnings as we upgraded 
> Ansible 2.3 to 2.7.9 (CentOS 7.4)
> And I have this code:
> 
> - name: Install required system packages
>   yum:
> name: "{{ item }}"
> state: 'present'
>   with_items:
> - "{{ base_packages }}"
> - "{{ additional_packages | d(omit) }}"

Assuming base_packages and additional_packages are lists, try:

- name: install pkgs
  yum:
state: present
name: "{{ base_pkgs + additional_pkgs | default([]) }}"

Ansible wants a flat list here. The suggestion in the deprecation
warning thinks both are just normal values and wants you to put them
into a list.

But if you already have lists, merge them with + as in the above code.

HTH,
Sebastian

-- 
Sebastian Meyer
Linux Consultant & Trainer
Mail: me...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5560e97b-8eae-16b4-c4c7-63377eb6f134%40b1-systems.de.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] yum module gives "AttributeError: 'list' object has no attribute 'strip'" on list of items

2019-03-27 Thread Robin Roevens
Hi all

I'm currently trying to get rid of all deprecation warnings as we upgraded 
Ansible 2.3 to 2.7.9 (CentOS 7.4)
And I have this code:

- name: Install required system packages
  yum:
name: "{{ item }}"
state: 'present'
  with_items:
- "{{ base_packages }}"
- "{{ additional_packages | d(omit) }}"

Which triggers the warning:
[DEPRECATION WARNING]: Invoking "yum" only once while using a loop via 
squash_actions is deprecated. Instead of using a loop to supply multiple 
items and specifying `name: "{{ item }}"`, please use `name: ['{{ 
base_packages }}', '{{ additional_packages | d(omit) }}']` and remove the 
loop. This feature will be removed in version 2.11. Deprecation warnings 
can be disabled by setting deprecation_warnings=False in ansible.cfg.

So I did exactly as I'm told and changed the yaml to:
- name: Install required system packages
  yum:
name: ["{{ base_packages }}", "{{ additional_packages | d(omit) }}"]
state: 'present'

However instead of the expected profit, I now get this error:
fatal: [**]: FAILED! => {"changed": false, "module_stderr": "Shared 
connection to  closed.\r\n", "module_stdout": "Traceback (most 
recent call last):\r\n  File 
\"/home/ops/.ansible/tmp/ansible-tmp-1553701282.46-91084623823669/AnsiballZ_yum.py\",
 
line 113, in \r\n_ansiballz_main()\r\n  File 
\"/home/ops/.ansible/tmp/ansible-tmp-1553701282.46-91084623823669/AnsiballZ_yum.py\",
 
line 105, in _ansiballz_main\r\ninvoke_module(zipped_mod, temp_path, 
ANSIBALLZ_PARAMS)\r\n  File 
\"/home/ops/.ansible/tmp/ansible-tmp-1553701282.46-91084623823669/AnsiballZ_yum.py\",
 
line 48, in invoke_module\r\nimp.load_module('__main__', mod, module, 
MOD_DESC)\r\n  File \"/tmp/ansible_yum_payload_PO7N0L/__main__.py\", line 
1571, in \r\n  File 
\"/tmp/ansible_yum_payload_PO7N0L/__main__.py\", line 1566, in main\r\n  
File \"/tmp/ansible_yum_payload_PO7N0L/__main__.py\", line 375, in 
__init__\r\n  File 
\"/tmp/ansible_yum_payload_PO7N0L/ansible_yum_payload.zip/ansible/module_utils/yumdnf.py\",
 
line 79, in __init__\r\n*AttributeError: 'list' object has no attribute 
'strip'*\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact 
error", "rc": 1}

I checked on the control machine, there are no old versions of the modules 
laying around. Also I tried using the package module, but that generates 
exactly the same error.
Is this because, in this case, {{ additional_packages }} is empty ? If so, 
how should I then handle this instead of d(omit) ?

Thanks!

Robin

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ed3f6fc2-70d0-4c87-8b16-23e8163a5029%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.