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...'])
| map('regex_replace', '^(.*?)/(.*)', '\\1') | list }}"
On Monday, February 3, 2020 at 11:57:21 PM UTC-8, Dick Visser wrote:
>
> 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
>
>
> 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
> 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...'])
> | map('regex_replace', '^(.*?)\/(.*)', '\\1') | list }}"
>
> - debug: var=updates
>
>
> On Tue, 4 Feb 2020 at 01:12, Work-Hard <[email protected] <javascript:>>
> wrote:
> >
> > 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 is defined
> >
> >
> > playbook output
> >
> > PLAY [myotherserver]
> *****************************************************************************************************************************
>
>
> >
> > TASK [Gathering Facts]
> ***************************************************************************************************************************
>
>
> > ok: [10.0.2.236]
> >
> > TASK [apt-get update]
> ****************************************************************************************************************************
>
>
> > ok: [10.0.2.236]
> >
> > TASK [get list of pending upgrades]
> **************************************************************************************************************
>
>
> > 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
> >
> > --
> > 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 [email protected] <javascript:>.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9de09a5f-1173-43b7-a2d7-3332ba0e060d%40googlegroups.com.
>
>
>
>
>
> --
> Dick Visser
> Trust & Identity Service Operations Manager
> GÉANT
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/2a6f8087-d857-43a5-b2cd-fb09f47a7e6c%40googlegroups.com.