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

changed: false always #49

Closed
anthr76 opened this issue Sep 19, 2021 · 4 comments · Fixed by #50
Closed

changed: false always #49

anthr76 opened this issue Sep 19, 2021 · 4 comments · Fixed by #50

Comments

@anthr76
Copy link

anthr76 commented Sep 19, 2021

SUMMARY

Runs with community.routeros.command never showed changed even though things are changing.

ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
ansible 2.9.26
  config file = /var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg
  configured module search path = ['/var/home/anthonyjrabbito/dev/infra/ansible/library', '/var/home/anthonyjrabbito/dev/infra/ansible/kubespray/library', '/var/home/anthonyjrabbito/dev/infra/ansible/k8s-cluster-installation/ansible/library']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.10.0rc2 (default, Sep  8 2021, 00:00:00) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]
COLLECTION VERSION
2.0.0-a1
CONFIGURATION
ANSIBLE_PIPELINING(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = -o ControlMaster=auto -o ControlPersist=30m -o ConnectionAttempts=100 -o UserKnownHostsFil>
CACHE_PLUGIN(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = /tmp
CACHE_PLUGIN_TIMEOUT(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = 7200
DEFAULT_CALLBACK_WHITELIST(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = ['profile_tasks']
DEFAULT_GATHERING(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = smart
DEFAULT_HOST_LIST(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = ['/var/home/anthonyjrabbito/dev/infra/ansible/inventory/inventory.ini']
DEFAULT_MODULE_PATH(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = ['/var/home/anthonyjrabbito/dev/infra/ansible/library', '/var/home/anthonyjrabbito/dev/>
DEFAULT_ROLES_PATH(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = ['/var/home/anthonyjrabbito/dev/infra/ansible/roles', '/var/home/anthonyjrabbito/dev/inf>
DEFAULT_STDOUT_CALLBACK(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = default
DEFAULT_STRATEGY_PLUGIN_PATH(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = ['/var/home/anthonyjrabbito/dev/infra/ansible/plugins/mitogen/ansible_mitogen/>
DEPRECATION_WARNINGS(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = False
DISPLAY_SKIPPED_HOSTS(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = False
HOST_KEY_CHECKING(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = False
INVENTORY_IGNORE_EXTS(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = ['~', '.orig', '.bak', '.ini', '.cfg', '.retry', '.pyc', '.pyo', '.creds', '.gpg']
INVENTORY_IGNORE_PATTERNS(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = ['artifacts', 'credentials']
PERSISTENT_COMMAND_TIMEOUT(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = 600
TRANSFORM_INVALID_GROUP_CHARS(/var/home/anthonyjrabbito/dev/infra/ansible/ansible.cfg) = ignore
OS / ENVIRONMENT
STEPS TO REPRODUCE
- name: system | configure hostname
  community.routeros.command:
    commands:
        - /system identity set name="{{ system.hostname }}"
EXPECTED RESULTS

Ansible will report a change.

ACTUAL RESULTS
ok: [sw-core-1.scr1.rabbito.tech] => (item={'port': 'sfp-sfpplus4', 'pvid': 10}) => {                                                                                  
    "ansible_loop_var": "item",                                                                                                                                        
    "changed": false,                                                                                                                                                  
    "invocation": {                                                                                                                                                    
        "module_args": {                                                                                                                                               
            "commands": [                                                                                                                                              
                "/interface bridge port add bridge=bridge interface=sfp-sfpplus4 pvid=10",                                                                             
                "/interface bridge vlan add bridge=bridge untagged=sfp-sfpplus4 vlan-ids=10",                                                                          
                "/interface ethernet set sfp-sfpplus4 comment=\"configured by Ansible\""                                                                               
            ],                                                                                                                                                         
            "interval": 1,                                                                                                                                             
            "match": "all",                                                                                                                                            
            "retries": 10,                                                                                                                                             
            "wait_for": null                                                                                                                                           
        }                                                                                                                                                              
    },                                                                                                                                                                 
    "item": {                                                                                                                                                          
        "port": "sfp-sfpplus4",                                                                                                                                        
        "pvid": 10                                                                                                                                                     
    },                                                                                                                                                                 
    "stdout": [                                                                                                                                                        
        "",                                                                                                                                                            
        "",       
        ""
    ],         
    "stdout_lines": [
        [  
            ""
        ],
        [            
            ""
        ],    
        [ 
            ""
        ]     
    ]     
}   
@felixfontein
Copy link
Collaborator

This comes from https://github.com/ansible-collections/community.routeros/blob/main/plugins/modules/command.py#L171, and is definitely wrong. It's good that we are still preparing 2.0.0, so we can add another breaking change :)

@anthr76
Copy link
Author

anthr76 commented Sep 19, 2021

It's odd.. it looks like that line has never changed, but I could've sworn there was a point in time this collection would report if things actually changed..

@felixfontein
Copy link
Collaborator

It looks like the command module never did that. You can of course use changed_when to indicate when something changed; maybe you've seen one such use in the past?

In fact the correct behavior would be to always indicate changed=true, since it's impossible to know when something really changed. Determining this is the job of the caller. (This is true for basically all command modules for all operating systems, since it is impossible to say for an arbitrary command whether there has been a change or not.)

@felixfontein
Copy link
Collaborator

I created a fix in #50.

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

Successfully merging a pull request may close this issue.

2 participants