Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing MAC address strings through the ansible.utils.macaddr filter causes some to be maimed. #389

Open
MrDrMcCoy opened this issue Feb 14, 2025 · 1 comment
Assignees

Comments

@MrDrMcCoy
Copy link

SUMMARY

Passing MAC address strings through the ansible.utils.macaddr filter causes some to be maimed.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible.utils.macaddr

ANSIBLE VERSION
$ ansible --version
ansible [core 2.18.2]
  config file = /home/jmccoy/.ansible.cfg
  configured module search path = ['/home/jmccoy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules', '/home/jmccoy/git/configMgmt/ansible/plugins/modules', '/home/jmccoy/configMgmt/ansible/plugins/modules', '/home/jmccoy/.local/lib/python3.10/site-packages/ansible/plugins/modules', '/home/jmccoy/.local/lib/python3.11/site-packages/ansible/plugins/modules', '/home/jmccoy/.local/lib/python3.12/site-packages/ansible/plugins/modules']
  ansible python module location = /home/jmccoy/.local/lib/python3.12/site-packages/ansible
  ansible collection location = /home/jmccoy/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/jmccoy/.local/bin/ansible
  python version = 3.12.3 (main, Jan 17 2025, 18:03:48) [GCC 13.3.0] (/usr/bin/python3)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
$ ansible-galaxy collection list ansible.utils

# /home/jmccoy/.ansible/collections/ansible_collections
Collection    Version
------------- -------
ansible.utils 5.1.2

# /home/jmccoy/.local/lib/python3.12/site-packages/ansible_collections
Collection    Version
------------- -------
ansible.utils 5.1.2
#####CONFIGURATION
$ ansible-config dump --only-changed -t all | cat
ACTION_WARNINGS(/home/jmccoy/.ansible.cfg) = False
CACHE_PLUGIN(/home/jmccoy/.ansible.cfg) = memory
CACHE_PLUGIN_CONNECTION(/home/jmccoy/.ansible.cfg) = /tmp/ansible.cache
CACHE_PLUGIN_PREFIX(/home/jmccoy/.ansible.cfg) = cacheit
CONFIG_FILE() = /home/jmccoy/.ansible.cfg
DEFAULT_BECOME(/home/jmccoy/.ansible.cfg) = True
DEFAULT_CALLBACK_PLUGIN_PATH(/home/jmccoy/.ansible.cfg) = ['/home/jmccoy/git/configMgmt/ansible/plugins/callback', '/home/jmccoy/configMgmt/ansible/plugins/callback', '/home/jmccoy/.ansible/plugins/callback', '/usr/share/ansible/plugins/callback', '/home/jmccoy/.local/lib/python3.10/site-packages/ansible/plugins/callback', '/home/jmccoy/.local/lib/python3.11/site-packages/ansible/plugins/callback', '/home/jmccoy/.local/lib/python3.12/site-packages/ansible/plugins/callback']
DEFAULT_CONNECTION_PLUGIN_PATH(/home/jmccoy/.ansible.cfg) = ['/home/jmccoy/git/configMgmt/ansible/plugins/connection', '/home/jmccoy/configMgmt/ansible/plugins/connection', '/home/jmccoy/.ansible/plugins/connection', '/usr/share/ansible/plugins/connection', '/home/jmccoy/.local/lib/python3.10/site-packages/ansible/plugins/connection', '/home/jmccoy/.local/lib/python3.11/site-packages/ansible/plugins/connection', '/home/jmccoy/.local/lib/python3.12/site-packages/ansible/plugins/connection']
DEFAULT_FORKS(/home/jmccoy/.ansible.cfg) = 32
DEFAULT_GATHERING(/home/jmccoy/.ansible.cfg) = implicit
DEFAULT_HASH_BEHAVIOUR(/home/jmccoy/.ansible.cfg) = replace
DEFAULT_HOST_LIST(/home/jmccoy/.ansible.cfg) = ['/home/jmccoy/git/configMgmt/ansible/hosts', '/home/jmccoy/configMgmt/ansible/hosts', '/etc/ansible/hosts']
DEFAULT_LOAD_CALLBACK_PLUGINS(/home/jmccoy/.ansible.cfg) = True
DEFAULT_LOCAL_TMP(/home/jmccoy/.ansible.cfg) = /tmp/ansible-local-2411714_gl_5xjj
DEFAULT_LOG_PATH(/home/jmccoy/.ansible.cfg) = /home/jmccoy/.ansible/ansible.log
DEFAULT_LOOKUP_PLUGIN_PATH(/home/jmccoy/.ansible.cfg) = ['/home/jmccoy/.ansible/plugins/lookup', '/usr/share/ansible/plugins/lookup', '/home/jmccoy/git/configMgmt/ansible/plugins/lookup', '/home/jmccoy/configMgmt/ansible/plugins/lookup', '/home/jmccoy/.local/lib/python3.10/site-packages/ansible/plugins/lookup', '/home/jmccoy/.local/lib/python3.11/site-packages/ansible/plugins/lookup', '/home/jmccoy/.local/lib/python3.12/site-packages/ansible/plugins/lookup']
DEFAULT_MANAGED_STR(/home/jmccoy/.ansible.cfg) = Do not manually edit this file!  This file is managed by Ansible.  Make all changes in the appropriate Ansible template, then push the changes.  If you do not follow this procedure, your changes will be overwritten on the next push!
DEFAULT_MODULE_NAME(/home/jmccoy/.ansible.cfg) = shell
DEFAULT_MODULE_PATH(/home/jmccoy/.ansible.cfg) = ['/home/jmccoy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules', '/home/jmccoy/git/configMgmt/ansible/plugins/modules', '/home/jmccoy/configMgmt/ansible/plugins/modules', '/home/jmccoy/.local/lib/python3.10/site-packages/ansible/plugins/modules', '/home/jmccoy/.local/lib/python3.11/site-packages/ansible/plugins/modules', '/home/jmccoy/.local/lib/python3.12/site-packages/ansible/plugins/modules']
DEFAULT_POLL_INTERVAL(/home/jmccoy/.ansible.cfg) = 2
DEFAULT_ROLES_PATH(/home/jmccoy/.ansible.cfg) = ['/home/jmccoy/git/configMgmt/ansible/roles', '/home/jmccoy/ansible-personal/roles']
DEFAULT_STDOUT_CALLBACK(/home/jmccoy/.ansible.cfg) = community.general.yaml
DEFAULT_STRATEGY(/home/jmccoy/.ansible.cfg) = ansible.builtin.host_pinned
DEFAULT_TIMEOUT(/home/jmccoy/.ansible.cfg) = 30
DIFF_ALWAYS(/home/jmccoy/.ansible.cfg) = True
DISPLAY_ARGS_TO_STDOUT(/home/jmccoy/.ansible.cfg) = True
DISPLAY_SKIPPED_HOSTS(/home/jmccoy/.ansible.cfg) = True
DUPLICATE_YAML_DICT_KEY(/home/jmccoy/.ansible.cfg) = ignore
EDITOR(env: EDITOR) = micro
HOST_KEY_CHECKING(/home/jmccoy/.ansible.cfg) = False
INJECT_FACTS_AS_VARS(/home/jmccoy/.ansible.cfg) = True
INVENTORY_CACHE_ENABLED(/home/jmccoy/.ansible.cfg) = True
INVENTORY_CACHE_PLUGIN(/home/jmccoy/.ansible.cfg) = community.general.yaml
INVENTORY_UNPARSED_IS_FAILED(/home/jmccoy/.ansible.cfg) = True
PERSISTENT_COMMAND_TIMEOUT(/home/jmccoy/.ansible.cfg) = 30
PERSISTENT_CONNECT_RETRY_TIMEOUT(/home/jmccoy/.ansible.cfg) = 5
PERSISTENT_CONNECT_TIMEOUT(/home/jmccoy/.ansible.cfg) = 45
RETRY_FILES_ENABLED(/home/jmccoy/.ansible.cfg) = True
SYSTEM_WARNINGS(/home/jmccoy/.ansible.cfg) = False
TASK_TIMEOUT(/home/jmccoy/.ansible.cfg) = 300
USE_PERSISTENT_CONNECTIONS(/home/jmccoy/.ansible.cfg) = True

GALAXY_SERVERS:


CACHE:
=====

jsonfile:
________
_prefix(/home/jmccoy/.ansible.cfg) = cacheit
_uri(/home/jmccoy/.ansible.cfg) = /tmp/ansible.cache

CALLBACK:
========

default:
_______
check_mode_markers(env: ANSIBLE_CHECK_MODE_MARKERS) = True
display_skipped_hosts(/home/jmccoy/.ansible.cfg) = True
show_task_path_on_failure(env: ANSIBLE_SHOW_TASK_PATH_ON_FAILURE) = True

CONNECTION:
==========

paramiko_ssh:
____________
host_key_checking(env: ANSIBLE_PARAMIKO_HOST_KEY_CHECKING) = False
ssh_args(/home/jmccoy/.ansible.cfg) = -C -o ControlMaster=auto -o ControlPersist=yes -o ServerAliveInterval=2 -o ServerAliveCountMax=15 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no
timeout(/home/jmccoy/.ansible.cfg) = 30
use_persistent_connections(/home/jmccoy/.ansible.cfg) = True

ssh:
___
host_key_checking(/home/jmccoy/.ansible.cfg) = False
pipelining(/home/jmccoy/.ansible.cfg) = True
reconnection_retries(/home/jmccoy/.ansible.cfg) = 2
ssh_args(/home/jmccoy/.ansible.cfg) = -C -o ControlMaster=auto -o ControlPersist=yes -o ServerAliveInterval=2 -o ServerAliveCountMax=15 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no
timeout(/home/jmccoy/.ansible.cfg) = 30

SHELL:
=====

sh:
__
remote_tmp(/home/jmccoy/.ansible.cfg) = /tmp
OS / ENVIRONMENT
cat /etc/os-release
NAME="TUXEDO OS"
VERSION="24.04.1 LTS"
ID=tuxedo
ID_LIKE="ubuntu debian"
PRETTY_NAME="TUXEDO OS"
VERSION_ID="24.04"
HOME_URL="https://tuxedocomputers.com/"
SUPPORT_URL="https://support.tuxedocomputers.com/"
BUG_REPORT_URL="https://gitlab.com/tuxedocomputers/development/tuxedo_os/os"
PRIVACY_POLICY_URL="https://www.tuxedocomputers.com/en/Privacy-policy.tuxedo"
VERSION_CODENAME=noble
UBUNTU_CODENAME=noble
STEPS TO REPRODUCE
- ansible.builtin.fail:
    msg: |-
      {{
        ansible_facts.interfaces
        | map('replace', '-', '_')
        | map('extract', ansible_facts)
        | selectattr('macaddress', 'defined')
        | map(attribute='macaddress')
        | map('ansible.utils.macaddr', 'unix')
        | to_nice_yaml
      }}
EXPECTED RESULTS
fatal: #[kvm-sac0-0001]: FAILED! => changed=false
  msg: |-
    - 52:54:00:28:ea:7f
    - fe:54:00:ae:fa:bb
    - 00:25:90:ba:36:c1
    - 00:25:90:ba:36:c0
    - 52:54:00:6a:70:40
    - 52:54:00:01:9b:8c
    - fe:54:00:3f:c3:c2
    - fe:54:00:b9:b9:e9
    - de:ae:f6:59:d2:10
    - 00:25:90:ba:36:c0
    - 52:54:00:29:8d:83
    - 00:25:90:ba:34:2e
    - 52:54:00:b0:15:db
    - fe:54:00:7e:c3:9b
    - fe:54:00:c6:18:84
    - 52:54:00:d4:d8:2a
    - aa:d1:85:0f:02:63
    - fe:54:00:ac:48:ca
    - 52:54:00:61:46:cd
    - fe:54:00:22:69:d1
    - 00:25:90:ba:34:2f
    - fe:54:00:1c:a8:66
    - fe:54:00:53:6c:9e
ACTUAL RESULTS
fatal: #[kvm-sac0-0001]: FAILED! => changed=false
  msg: |-
    - 52:54:0:28:ea:7f
    - fe:54:0:ae:fa:bb
    - 0:25:90:ba:36:c1
    - 0:25:90:ba:36:c0
    - 52:54:0:6a:70:40
    - 52:54:0:1:9b:8c
    - fe:54:0:3f:c3:c2
    - fe:54:0:b9:b9:e9
    - de:ae:f6:59:d2:10
    - 0:25:90:ba:36:c0
    - 52:54:0:29:8d:83
    - 0:25:90:ba:34:2e
    - 52:54:0:b0:15:db
    - fe:54:0:7e:c3:9b
    - fe:54:0:c6:18:84
    - 52:54:0:d4:d8:2a
    - aa:d1:85:f:2:63
    - fe:54:0:ac:48:ca
    - 52:54:0:61:46:cd
    - fe:54:0:22:69:d1
    - 0:25:90:ba:34:2f
    - fe:54:0:1c:a8:66
    - fe:54:0:53:6c:9e
@MrDrMcCoy
Copy link
Author

Looking at the code:

mac_linux.word_fmt = "%.2x"

It looks like the linux format extension performs additional hex formatting and handles this correctly:

- ansible.builtin.fail:
    msg: |-
      {{
        ansible_facts.interfaces
        | map('replace', '-', '_')
        | map('extract', ansible_facts)
        | selectattr('macaddress', 'defined')
        | map(attribute='macaddress')
        | map('ansible.utils.macaddr', 'unix')
        | to_nice_yaml
      }}
fatal: #[kvm-sac0-0001]: FAILED! => changed=false
  msg:
    - 52:54:00:28:ea:7f
    - fe:54:00:ae:fa:bb
    - 00:25:90:ba:36:c1
    - 00:25:90:ba:36:c0
    - 52:54:00:6a:70:40
    - 52:54:00:01:9b:8c
    - fe:54:00:3f:c3:c2
    - fe:54:00:b9:b9:e9
    - de:ae:f6:59:d2:10
    - 00:25:90:ba:36:c0
    - 52:54:00:29:8d:83
    - 00:25:90:ba:34:2e
    - 52:54:00:b0:15:db
    - fe:54:00:7e:c3:9b
    - fe:54:00:c6:18:84
    - 52:54:00:d4:d8:2a
    - aa:d1:85:0f:02:63
    - fe:54:00:ac:48:ca
    - 52:54:00:61:46:cd
    - fe:54:00:22:69:d1
    - 00:25:90:ba:34:2f
    - fe:54:00:1c:a8:66
    - fe:54:00:53:6c:9e

I propose similarly handling all MAC address formats in this fashion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants