[mythtv] Proposed Ansible Changes, Getting ready for ansible 2.11

Bill Meek keemllib at gmail.com
Wed Aug 15 03:15:10 UTC 2018


Hi all,

In Ansible 2.5, the 'loop' keyword is now preferred over the 'with_item' keyword.
Mythbuntu 16.04 uses 2.0.0.2, Ubuntu 18.04 uses 2.5.1

But, both loop and with_* are no longer the keywords of choice for things like apt/yum...

The stimulus for doing this is the following, found when running Ansible 2.7:

   [DEPRECATION WARNING]: Invoking "apt" 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: [u'git', u'g++', u'make', u'build-essential', u'yasm', u'automake', u'libtool',
   u'ccache', u'pkg-config']` 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.

Comment from: https://docs.ansible.com/ansible/devel/user_guide/playbooks_loops.html

   - name: optimal yum
     yum:
       name: "{{list_of_packages}}"
       state: present

   - name: non optimal yum, not only slower but might cause issues with interdependencies
     yum:
       name: "{{item}}"
       state: present
     loop: "{{list_of_packages}}"

So here's my proposal, just a few lines from the mythtv-deb tasks' directory:

bill at ofc0:~/source/mythtv-ansible$ cat roles/mythtv-deb/tasks/main.yml

# EXISTING:
- name: install compilers and build essentials
   apt:  name={{ item }} state=present
   with_items:
     - git
     - g++
     - make
     - build-essential
     - yasm
     - automake
     - libtool
     - ccache
     - pkg-config

# NEW:
- name: add compilers and build essentials
   set_fact:
     deb_pkg_lst:
     - git
     - g++
     - make
     - build-essential
     - yasm
     - automake
     - libtool
     - ccache
     - pkg-config

# EXISTING:
- name: install compilers and build essentials 2 (ubuntu)
   apt:  name={{ item }} state=present
   when: ansible_distribution == "Ubuntu" and ansible_lsb.major_release|int >= 15
   with_items:
     - libtool-bin

# NEW (simple case, just one package. Max. is 16):
- name: add compilers and build essentials 2 (ubuntu)
   set_fact:
     deb_pkg_lst:
       - '{{ deb_pkg_lst }}'
       - libtool-bin
   when: ansible_distribution == "Ubuntu" and ansible_lsb.major_release|int >= 15

...

# NEW single apt: does all packages (in this main.yml) at once:
- name: install mythtv-deb packages
   apt:  name={{ lookup('flattened', deb_pkg_lst ) }} state=present


Any comments? I'm willing to convert playbooks, starting with mythtv-deb.
That's the only thing I've tested (Mythbuntu 16.04 and Ubuntu 18.04.)

I've also done another solution by giving names to each set of packages
and putting that list in the vars directory alongside of the tasks directory.
I think the above is easier to implement and maintain though.

-- 
Bill


More information about the mythtv-dev mailing list