Search code examples
ansiblemikrotik

ansible-playbook ignores '--check' parameter?


As testing a simple Ansible playbook

--- 
- hosts: mikrotiks
  connection: network_cli 
  gather_facts: no 

  vars: 

    ansible_network_os: routeros 
    ansible_user: admin 

  tasks: 

  - name: Add Basic FW Rules 
    routeros_command: 
      commands: 
        - /ip firewall nat add chain=srcnat out-interface=ether1 action=masquerade

on my mikrotik router, I used the command with --check argument

ansible-playbook -i hosts mikrotik.yml --check

but it seems that tasks actually got executed.

PLAY [mikrotiks] **************************************************************************************************************************************

TASK [Add Basic FW Rules] **************************************************************************************************************************************
changed: [192.168.1.82]

PLAY RECAP **************************************************************************************************************************************
192.168.1.82               : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

ansible.cfg file is the default configuration after fresh install.


Solution

  • According the documentation command module – Run commands on remote devices running MikroTik RouterOS

    The module always indicates a (changed) status. You can use the changed_when task property to determine whether a command task actually resulted in a change or not.

    Since the module is part of the community.routeros collection I had a short look into the source there and found that is supporting check_mode according

        module = AnsibleModule(argument_spec=argument_spec,
                               supports_check_mode=True)
    

    So you will need to follow up with defining "changed".