fortinet-ansible-dev / ansible-galaxy-fortios-collection

GNU General Public License v3.0
84 stars 48 forks source link

Unknown action 0 Command fail. Return code -1 #334

Closed corpslave69 closed 1 month ago

corpslave69 commented 1 month ago

I'm trying to execute commands with fortios module via ssh - username and password. (Not ssh key)

'"'"'echo ~admin && sleep 0'"'"'' is being used by ssh even though I have mentioned ansible_network_os=fortinet.fortios.fortios in the inventory file.

The commands using raw works but I'm unable to use any of the fortios modules. The same error occurs everytime.

hosts_css (Inventory):

[testing]
Hello ansible_host=10.172.139.2 ansible_user=admin ansible_password=<password> ansible_ssh_extra_args='-o StrictHostKeyChecking=no' ansible_connection=ssh

[all:vars]
ansible_network_os=fortinet.fortios.fortios

pls.yml (playbook):

- hosts: testing
  gather_facts: no
  collections:
    - fortinet.fortios
  tasks:
    - name: Get system status using CLI
      raw: get system status
      register: system_status_output

    - debug:
        var: system_status_output.stdout_lines

    - name: Get license status
      fortinet.fortios.fortios_monitor_fact:
        vdom: root
        selectors:
            - selector: license_status
            - selector: system_status
            - selector: firewall_security-policy
              params:
                  policyid: '1'

ansible.cfg:

[defaults]
interpreter_python=/usr/local/bin/python
host_key_checking = false

Task with raw module gets executed properly:

TASK [Get system status using CLI] ************************************************************************************************************************************************************************
task path: /home/tejas/Ansible/pls.yml:7
<10.172.139.2> ESTABLISH SSH CONNECTION FOR USER: admin
<10.172.139.2> SSH: EXEC sshpass -d12 ssh -vvvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o 'ControlPath="/home/tejas/.ansible/cp/4a0f0783ec"' -tt 10.172.139.2 'get system status'
<10.172.139.2> (0, b'trondheim02-vpn-1-mgmt # Version: FortiGate-100F v6.2.3,build6188,200109 (GA)\r\nFirmware Signature: certified

.......
debug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to 10.172.139.2 closed.\r\n')

This is the debug output for Get license status task which I tried to execute with fortinet.fortios.fortios_monitor_fact:

TASK [Get license status] *********************************************************************************************************************************************************************************
task path: /home/tejas/Ansible/pls.yml:14
<10.172.139.2> ESTABLISH SSH CONNECTION FOR USER: admin
<10.172.139.2> SSH: EXEC sshpass -d12 ssh -vvvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o 'ControlPath="/home/tejas/.ansible/cp/4a0f0783ec"' 10.172.139.2 '/bin/sh -c '"'"'echo ~admin && sleep 0'"'"''
<10.172.139.2> (0, b'trondheim02-vpn-1-mgmt # \ntrondheim02-vpn-1-mgmt # ', b'OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 8340\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\n8278: Unknown action 0\nCommand fail. Return code -1\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<10.172.139.2> ESTABLISH SSH CONNECTION FOR USER: admin
<10.172.139.2> SSH: EXEC sshpass -d12 ssh -vvvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o 'ControlPath="/home/tejas/.ansible/cp/4a0f0783ec"' 10.172.139.2 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo trondheim02-vpn-1-mgmt #/.ansible/tmp `"&& mkdir "` echo trondheim02-vpn-1-mgmt #/.ansible/tmp/ansible-tmp-1721587091.1048012-8344-202590340256464 `" && echo ansible-tmp-1721587091.1048012-8344-202590340256464="` echo trondheim02-vpn-1-mgmt #/.ansible/tmp/ansible-tmp-1721587091.1048012-8344-202590340256464 `" ) && sleep 0'"'"''
<10.172.139.2> (0, b'trondheim02-vpn-1-mgmt # \ntrondheim02-vpn-1-mgmt # ', b'OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 8340\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\n8278: Unknown action 0\nCommand fail. Return code -1\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
Using module file /home/tejas/.ansible/collections/ansible_collections/fortinet/fortios/plugins/modules/fortios_monitor_fact.py
<10.172.139.2> PUT /home/tejas/.ansible/tmp/ansible-local-8321msrd7qqs/tmp2l6h9yru TO trondheim02-vpn-1-mgmt #/AnsiballZ_fortios_monitor_fact.py
<10.172.139.2> SSH: EXEC sshpass -d12 sftp -o BatchMode=no -b - -vvvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o 'ControlPath="/home/tejas/.ansible/cp/4a0f0783ec"' '[10.172.139.2]'
[WARNING]: sftp transfer mechanism failed on [10.172.139.2]. Use ANSIBLE_DEBUG=1 to see detailed information
<10.172.139.2> SSH: EXEC sshpass -d12 scp -vvvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o 'ControlPath="/home/tejas/.ansible/cp/4a0f0783ec"' /home/tejas/.ansible/tmp/ansible-local-8321msrd7qqs/tmp2l6h9yru '[10.172.139.2]:'"'"'trondheim02-vpn-1-mgmt #/AnsiballZ_fortios_monitor_fact.py'"'"''
[WARNING]: scp transfer mechanism failed on [10.172.139.2]. Use ANSIBLE_DEBUG=1 to see detailed information
<10.172.139.2> ESTABLISH SSH CONNECTION FOR USER: admin
<10.172.139.2> SSH: EXEC sshpass -d12 ssh -vvvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o 'ControlPath="/home/tejas/.ansible/cp/4a0f0783ec"' 10.172.139.2 'dd of=trondheim02-vpn-1-mgmt #/AnsiballZ_fortios_monitor_fact.py bs=65536'
<10.172.139.2> (0, b'trondheim02-vpn-1-mgmt # \ntrondheim02-vpn-1-mgmt # ', b'OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 8340\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\n8278: Unknown action 0\nCommand fail. Return code -1\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<10.172.139.2> (0, b'trondheim02-vpn-1-mgmt # \ntrondheim02-vpn-1-mgmt # ', b'OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 8340\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\n8278: Unknown action 0\nCommand fail. Return code -1\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<10.172.139.2> ESTABLISH SSH CONNECTION FOR USER: admin
<10.172.139.2> SSH: EXEC sshpass -d12 ssh -vvvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o 'ControlPath="/home/tejas/.ansible/cp/4a0f0783ec"' 10.172.139.2 '/bin/sh -c '"'"'chmod u+x '"'"'"'"'"'"'"'"'trondheim02-vpn-1-mgmt #/'"'"'"'"'"'"'"'"' '"'"'"'"'"'"'"'"'trondheim02-vpn-1-mgmt #/AnsiballZ_fortios_monitor_fact.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''
<10.172.139.2> (0, b'trondheim02-vpn-1-mgmt # \ntrondheim02-vpn-1-mgmt # ', b'OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 8340\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\n8278: Unknown action 0\nCommand fail. Return code -1\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<10.172.139.2> ESTABLISH SSH CONNECTION FOR USER: admin
<10.172.139.2> SSH: EXEC sshpass -d12 ssh -vvvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o 'ControlPath="/home/tejas/.ansible/cp/4a0f0783ec"' -tt 10.172.139.2 '/bin/sh -c '"'"'/usr/local/bin/python '"'"'"'"'"'"'"'"'trondheim02-vpn-1-mgmt #/AnsiballZ_fortios_monitor_fact.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''
<10.172.139.2> (0, b'trondheim02-vpn-1-mgmt # 8278: Unknown action 0\r\nCommand fail. Return code -1\r\n\r\ntrondheim02-vpn-1-mgmt # ', b'OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 8340\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to 10.172.139.2 closed.\r\n')
fatal: [Hello]: FAILED! => {
    "changed": false,
    "module_stderr": "OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 8340\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to 10.172.139.2 closed.\r\n",
    "module_stdout": "trondheim02-vpn-1-mgmt # 8278: Unknown action 0\r\nCommand fail. Return code -1\r\n\r\ntrondheim02-vpn-1-mgmt # ",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 0
}

I'm unable to use any fortios module as I'm getting the same error.

corpslave69 commented 1 month ago

I just figured out that ssh doesnt work with this module.