Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I send a variable to community.routeros.command? Ansible

I have a variable:

ok: [192.168.0.2] => {
  "_ip": [
    "192.168.0.3"
]

}

I’m trying to pass it to a command on routeros

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

- name: Ping
  community.routeros.command:
    commands: 'ping {{_ip}} count 5'
  register: ping

But it turns out to be a mistake

ok: [192.168.0.2] => {
"ping.stdout_lines": [
    [
        "p",
        "",
        "expected command name (line 1 column 7)"
    ]
]

}

I looked at what the error might be, it gave the following:

changed: [192.168.176.129] => {
"changed": true,
"invocation": {
    "module_args": {
        "commands": [
            "ping ['192.168.176.128'] count 5"
        ],
        "interval": 1,
        "match": "all",
        "retries": 10,
        "wait_for": null
    }
},
"stdout": [
    "p\n\nexpected command name (line 1 column 7)"
],
"stdout_lines": [
    [
        "p",
        "",
        "expected command name (line 1 column 7)"
    ]
]

}

How to fix it?

>Solution :

following your error, its seems _ip is a list, so

try:

commands: 'ping {{_ip.0}} count 5'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading