# Error while readin split part for updating Ubuntu packages - Should I include the path of splitpath,py in playbook ?

**URL:** <https://forum.ansible.com/t/error-while-readin-split-part-for-updating-ubuntu-packages-should-i-include-the-path-of-splitpath-py-in-playbook/32125>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [February 4, 2020, 12:11am UTC](https://forum.ansible.com/t/error-while-readin-split-part-for-updating-ubuntu-packages-should-i-include-the-path-of-splitpath-py-in-playbook/32125 "2020-02-04T00:11:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Work\_Email](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@Work\_Email](https://forum.ansible.com/u/Work_Email)\
**Post date:** [February 4, 2020, 12:11am UTC](https://forum.ansible.com/t/error-while-readin-split-part-for-updating-ubuntu-packages-should-i-include-the-path-of-splitpath-py-in-playbook/32125/1 "2020-02-04T00:11:50Z")

</div>

**Hello, Please see below**  
**ansible.cfg**

[defaults]  
inventory = ./hosts

splitpart.py = /etc/ansible/splitpart.py/

**splitpart.py**

def splitpart (value, index, char = ‘,’):  
if isinstance(value, (list, tuple)):  
ret =   
for v in value:  
ret.append(v.split(char)[index])  
return ret  
else:  
return value.split(char)[index]

class FilterModule(object):  
def filters(self):  
return {‘splitpart’: splitpart

**playbook**

tasks:

# do an “apt-get update”, to ensure latest package lists

- name: apt-get update  
apt:  
update-cache: yes  
changed\_when: 0

# get a list of packages that have updates

- name: get list of pending upgrades  
command: apt-get --simulate dist-upgrade  
args:  
warn: false # don’t warn us about apt having its own plugin  
register: apt\_simulate  
changed\_when: 0

# pick out list of pending updates from command output. This essentially

# takes the above output from “apt-get --simulate dist-upgrade”, and

# pipes it through “cut -f2 -d’ ’ | sort”

- name: parse apt-get output to get list of changed packages  
set\_fact:  
updates: ‘{{ apt\_simulate.stdout\_lines | select(“match”, "^Inst ") | list | splitpart(1, " ") | list | sort }}’  
changed\_when: 0

# tell user about packages being updated

- name: show pending updates  
debug:  
var: updates  
when: updates.0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\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.0.2.236]

TASK [parse apt-get output to get list of changed packages] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [10.0.2.236]: FAILED! =\> {“msg”: “template error while templating string: no filter named ‘splitpart’. String: {{ apt\_simulate.stdout\_lines | select("match", "^Inst ") | list | splitpart(1, " ") | list | sort }}”}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
10.0.2.236 : ok=3 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [February 4, 2020, 7:56am UTC](https://forum.ansible.com/t/error-while-readin-split-part-for-updating-ubuntu-packages-should-i-include-the-path-of-splitpath-py-in-playbook/32125/2 "2020-02-04T07:56:48Z")

</div>

Hii

"splitpath.py" isn't a valid key for the config file. The correct one  
is "filter\_plugins", see:  
[https://docs.ansible.com/ansible/latest/reference\_appendices/config.html#default-filter-plugin-path](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-filter-plugin-path)

But I don't see why you would need such heavy weapons if all you want  
is a list of package names that have pending updates.  
This should roughly do the same, without the complexity of custom filters:

- name: Check for pending updates  
&nbsp;&nbsp;become: true  
&nbsp;&nbsp;hosts: all

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: Update cache  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;update-cache: yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;changed\_when: false

&nbsp;&nbsp;&nbsp;&nbsp;- name: Fetch package list of updates  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: apt list --upgradable  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: aptlist

&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updates: "{{ aptlist.stdout\_lines | difference(['Listing...'])

> map('regex\_replace', '^(.\*?)\/(.\*)', '\\1') | list }}"

&nbsp;&nbsp;&nbsp;&nbsp;- debug: var=updates

---

<div class="post-metadata">

**Author:** ![Work\_Email](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@Work\_Email](https://forum.ansible.com/u/Work_Email)\
**Post date:** [February 4, 2020, 7:24pm UTC](https://forum.ansible.com/t/error-while-readin-split-part-for-updating-ubuntu-packages-should-i-include-the-path-of-splitpath-py-in-playbook/32125/3 "2020-02-04T19:24:35Z")

</div>

Great! Thanks that worked but I had to modify the syntax in the set fact to make it work.

- name: Check for pending updates  
become: true  
hosts: all

tasks:

- name: Update cache  
apt:  
update-cache: yes  
changed\_when: false

- name: Fetch package list of updates  
command: apt list --upgradable  
register: aptlist

- set\_fact:  
updates: "{{ aptlist.stdout\_lines | difference([‘Listing…’])
