/ Üllar Seerme

To easily test filters using 'ansible-console'

March 2, 2022

Today’s release of version 2.6.0 for ansible.netcommon broke at least some people’s environments and in the course of trying to debug that myself I wound up learning a bit more how to effectively use ‘ansible-console’. While I had known about ‘ansible-console’ for some time1, my usage of it had stayed relatively low, thus I didn’t really know how to best interact with it. Here’s how I validated that version 2.6.0 explicitly was to blame:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
$ ansible --version
ansible 2.10.14
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.8.10 (default, Jun  2 2021, 10:49:15) [GCC 9.4.0]

$ ansible-galaxy collection list ansible.netcommon

# /usr/local/lib/python3.8/dist-packages/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 1.2.1  

$ ansible-console localhost
[WARNING]: No inventory was parsed, only implicit localhost is available
Welcome to the ansible console.
Type help or ? to list commands.

root@localhost (1)[f:5]$ debug msg="{{ '192.168.0.1' | ipaddr }}"
localhost | SUCCESS => {
    "msg": "192.168.0.1"
}
root@localhost (1)[f:5]$ exit

$ ansible-galaxy collection install ansible.netcommon:2.6.0
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Installing 'ansible.netcommon:2.6.0' to '/root/.ansible/collections/ansible_collections/ansible/netcommon'
Downloading https://galaxy.ansible.com/download/ansible-netcommon-2.6.0.tar.gz to /root/.ansible/tmp/ansible-local-28gxj1aybi/tmprfki827q
ansible.netcommon (2.6.0) was installed successfully
Installing 'ansible.utils:2.5.1' to '/root/.ansible/collections/ansible_collections/ansible/utils'
Downloading https://galaxy.ansible.com/download/ansible-utils-2.5.1.tar.gz to /root/.ansible/tmp/ansible-local-28gxj1aybi/tmprfki827q
ansible.utils (2.5.1) was installed successfully

$ ansible-galaxy collection list ansible.netcommon

# /usr/local/lib/python3.8/dist-packages/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 1.2.1  

# /root/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 2.6.0  

$ ansible-console localhost
[WARNING]: No inventory was parsed, only implicit localhost is available
Welcome to the ansible console.
Type help or ? to list commands.

root@localhost (1)[f:5]$ debug msg="{{ '192.168.0.1' | ipaddr }}"
localhost | FAILED! => {
    "msg": "template error while templating string: No filter named 'ipaddr'.. String: {{ '192.168.0.1' | ipaddr }}"
}
root@localhost (1)[f:5]$ exit

$ ansible-galaxy collection install ansible.netcommon:2.5.1 --force
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Installing 'ansible.netcommon:2.5.1' to '/root/.ansible/collections/ansible_collections/ansible/netcommon'
Downloading https://galaxy.ansible.com/download/ansible-netcommon-2.5.1.tar.gz to /root/.ansible/tmp/ansible-local-43w7kl5evo/tmpbqlle7ku
ansible.netcommon (2.5.1) was installed successfully
Skipping 'ansible.utils' as it is already installed

$ ansible-console localhost
[WARNING]: No inventory was parsed, only implicit localhost is available
Welcome to the ansible console.
Type help or ? to list commands.

root@localhost (1)[f:5]$ debug msg="{{ '192.168.0.1' | ipaddr }}"
localhost | SUCCESS => {
    "msg": "192.168.0.1"
}

After that it was trivial to pin the version of in the collections requirements.yml file:

1
2
3
4
---
collections:
- name: ansible.netcommon
    version: '==2.5.1'

  1. Big shout-out to Ian Miell for bringing attention to it: https://zwischenzugs.com/2021/08/27/five-ansible-techniques-i-wish-id-known-earlier/ ↩︎

Page history