如何将变量发送到 community.routeros.command? Ansible的

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

我有一个变量:

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

}

我正在尝试将其传递给 routeros 上的命令

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

结果发现是错误的

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

}

我查看了错误可能是什么,它给出了以下内容:

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)"
    ]
]

}

如何解决?

根据你的错误,_ip 似乎是一个列表,所以

尝试:

commands: 'ping {{_ip.0}} count 5'