Ich versuche, das Ansible ios_command-Modul zu verwenden, um die Version des Routers abzurufen.Ansible ios_command-Modul schlägt fehl
Dies ist das Textbuch, das bei mir läuft:
---
- name: POC playbook
hosts: testlab
gather_facts: no
gather_subset: no
tasks:
- name: Show router version
ios_command:
commands: "show version"
Wenn der Wirt, Benutzer, Passwort und Verbindung in den Hosts definiert werden file:
[testlab]
<host>
[testlab]
ansible_connection=ssh
ansible_ssh_user=<user>
ansible_ssh_pass=<password>
Wenn ich ausführen, um die oben Textbuch die folgender Fehler auftritt:
fatal: [host]: FAILED! => {"failed": true, "msg": "failed to transfer file to \"` echo ~/.ansible/tmp/ansible-tmp-1490199866.45-395283935741 `\") && sleep 0'\"/ios_command.py:\n\nAdministratively disabled.\n"}
Ich kann ssh in den Router mit dem angegebenen Benutzer Führen Sie den Befehl "show version" aus und rufen Sie die erwartete Ausgabe ab. Also glaube ich nicht, dass es ein Erlaubnisproblem ist. Ich bin nicht sicher, was das Problem sein könnte, so würde jede Hilfe geschätzt werden.
Unten Sie können die Debug-Ausgabe
[[email protected] ansible]# ANSIBLE_DEBUG=1 ansible-playbook poc.yml | more
PLAY [POC playbook] ************************************************************
3448 1490196133.51064: Loading StrategyModule 'linear' from /usr/lib/python2.7/site-packages/ansible/plugins/strategy/linear.py
3448 1490196133.51466: getting the remaining hosts for this loop
3448 1490196133.51484: done getting the remaining hosts for this loop
3448 1490196133.51503: building list of next tasks for hosts
3448 1490196133.51512: getting the next task for host <host>
3448 1490196133.51524: done getting next task for host <host>
3448 1490196133.51535:^task is: TASK: meta (flush_handlers)
3448 1490196133.51543:^state is: HOST STATE: block=1, task=1, rescue=0, always=0, role=None, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child
state? (None), did rescue? False, did start at task? False
3448 1490196133.51550: done building task lists
3448 1490196133.51555: counting tasks in each state of execution
3448 1490196133.51562: done counting tasks in each state of execution:
num_setups: 0
num_tasks: 1
num_rescue: 0
num_always: 0
3448 1490196133.51567: advancing hosts in ITERATING_TASKS
3448 1490196133.51572: starting to advance hosts
3448 1490196133.51581: getting the next task for host <host>
3448 1490196133.51591: done getting next task for host <host>
3448 1490196133.51599:^task is: TASK: meta (flush_handlers)
3448 1490196133.51607:^state is: HOST STATE: block=1, task=1, rescue=0, always=0, role=None, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child
state? (None), did rescue? False, did start at task? False
3448 1490196133.51614: done advancing hosts to next task
3448 1490196133.52318: done queuing things up, now waiting for results queue to drain
3448 1490196133.52330: results queue empty
3448 1490196133.52337: checking for any_errors_fatal
3448 1490196133.52342: done checking for any_errors_fatal
3448 1490196133.52346: checking for max_fail_percentage
3448 1490196133.52351: done checking for max_fail_percentage
3448 1490196133.52356: checking to see if all hosts have failed and the running result is not ok
3448 1490196133.52362: done checking to see if all hosts have failed
[WARNING]: scp transfer mechanism failed on [<host>]. Use ANSIBLE_DEBUG=1 to see detailed information
3448 1490196133.52366: getting the remaining hosts for this loop
3448 1490196133.52376: done getting the remaining hosts for this loop
3448 1490196133.52394: building list of next tasks for hosts
3448 1490196133.52401: getting the next task for host <host>
3448 1490196133.52411: done getting next task for host <host>
3448 1490196133.52419:^task is: TASK: Show router version
3448 1490196133.52426:^state is: HOST STATE: block=2, task=1, rescue=0, always=0, role=None, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child
state? (None), did rescue? False, did start at task? False
3448 1490196133.52431: done building task lists
3448 1490196133.52436: counting tasks in each state of execution
3448 1490196133.52442: done counting tasks in each state of execution:
num_setups: 0
num_tasks: 1
num_rescue: 0
num_always: 0
3448 1490196133.52447: advancing hosts in ITERATING_TASKS
3448 1490196133.52451: starting to advance hosts
3448 1490196133.52456: getting the next task for host <host>
3448 1490196133.52466: done getting next task for host <host>
3448 1490196133.52475:^task is: TASK: Show router version
3448 1490196133.52483:^state is: HOST STATE: block=2, task=1, rescue=0, always=0, role=None, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child
state? (None), did rescue? False, did start at task? False
3448 1490196133.52488: done advancing hosts to next task
3448 1490196133.52501: getting variables
3448 1490196133.52507: in VariableManager get_vars()
3448 1490196133.52567: done with get_vars()
3448 1490196133.52592: done getting variables
3448 1490196133.52602: sending task start callback, copying the task so we can template it temporarily
3448 1490196133.52608: done copying, going to template now
3448 1490196133.52614: done templating
3448 1490196133.52619: here goes the callback...
TASK [Show router version] *****************************************************
3448 1490196133.52636: sending task start callback
3448 1490196133.52643: entering _queue_task() for <host>/ios_command
3448 1490196133.52649: Creating lock for ios_command
3448 1490196133.52899: worker is 1 (out of 1 available)
3448 1490196133.52947: exiting _queue_task() for <host>/ios_command
3448 1490196133.53031: done queuing things up, now waiting for results queue to drain
3448 1490196133.53040: waiting for pending results...
3794 1490196133.53535: running TaskExecutor() for <host>/TASK: Show router version
3794 1490196133.53614: in run()
3794 1490196133.53681: calling self._execute()
3794 1490196133.54559: Loading Connection 'ssh' from /usr/lib/python2.7/site-packages/ansible/plugins/connection/ssh.py
3794 1490196133.54837: Loading ShellModule 'csh' from /usr/lib/python2.7/site-packages/ansible/plugins/shell/csh.py
3794 1490196133.54905: Loading ShellModule 'fish' from /usr/lib/python2.7/site-packages/ansible/plugins/shell/fish.py
3794 1490196133.54994: Loading ShellModule 'powershell' from /usr/lib/python2.7/site-packages/ansible/plugins/shell/powershell.py
3794 1490196133.55026: Loading ShellModule 'sh' from /usr/lib/python2.7/site-packages/ansible/plugins/shell/sh.py
3794 1490196133.55078: Loading ShellModule 'sh' from /usr/lib/python2.7/site-packages/ansible/plugins/shell/sh.py (found_in_cache=True, class_only=False)
3794 1490196133.55101: in VariableManager get_vars()
3794 1490196133.55166: done with get_vars()
3794 1490196133.55218: Loading ActionModule 'normal' from /usr/lib/python2.7/site-packages/ansible/plugins/action/normal.py
3794 1490196133.55232: starting attempt loop
3794 1490196133.55239: running the handler
3794 1490196133.55307: ANSIBALLZ: Using lock for ios_command
3794 1490196133.55315: ANSIBALLZ: Acquiring lock
3794 1490196133.55324: ANSIBALLZ: Lock acquired: 34872464
3794 1490196133.55332: ANSIBALLZ: Creating module
3794 1490196133.90135: ANSIBALLZ: Writing module
3794 1490196133.90178: ANSIBALLZ: Renaming module
3794 1490196133.90195: ANSIBALLZ: Done creating module
3794 1490196133.90296: _low_level_execute_command(): starting
3794 1490196133.90307: _low_level_execute_command(): executing: /bin/sh -c '(umask 77 && mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1490196133.9-74490097367509 `" && echo ansible-tmp-1490196133.9-74490097367509="` echo ~/.ansible/tmp
/ansible-tmp-1490196133.9-74490097367509 `") && sleep 0'
3794 1490196134.17414: stdout chunk (state=2):
>>>
*******************************************************************
* This system is for the use of authorized users only. *
* Individuals using this computer system without authority, or in *
* excess of their authority, are subject to having all of their *
* activities on this system monitored and recorded by system *
* personnel. *
* *
* In the course of monitoring individuals improperly using this *
* system, or in the course of system maintenance, the activities *
* of authorized users may also be monitored. *
* *
* Anyone using this system expressly consents to such monitoring *
* and is advised that if such monitoring reveals possible *
* evidence of criminal activity, system personnel may provide the *
* evidence of such monitoring to law enforcement officials. *
*******************************************************************
<<<
3794 1490196134.18231: stdout chunk (state=3):
>>>
Line has invalid autocommand "/bin/sh -c '(umask 77 && mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1490196133.9-74490097367509 `" && echo ansible-tmp-1490196133.9-74490097367509="` echo ~/.ansible/tmp/ansible-tmp-1490196133.9-7449009736
7509 `") && sleep 0'"<<<
3794 1490196134.48451: stdout chunk (state=3):
>>><<<
3794 1490196134.48464: stderr chunk (state=3):
>>><<<
3794 1490196134.48504: _low_level_execute_command() done: rc=0, stdout=
*******************************************************************
* This system is for the use of authorized users only. *
* Individuals using this computer system without authority, or in *
* excess of their authority, are subject to having all of their *
* activities on this system monitored and recorded by system *
* personnel. *
* *
* In the course of monitoring individuals improperly using this *
* system, or in the course of system maintenance, the activities *
* of authorized users may also be monitored. *
* *
* Anyone using this system expressly consents to such monitoring *
* and is advised that if such monitoring reveals possible *
* evidence of criminal activity, system personnel may provide the *
* evidence of such monitoring to law enforcement officials. *
*******************************************************************
Line has invalid autocommand "/bin/sh -c '(umask 77 && mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1490196133.9-74490097367509 `" && echo ansible-tmp-1490196133.9-74490097367509="` echo ~/.ansible/tmp/ansible-tmp-1490196133.9-7449009736
7509 `") && sleep 0'", stderr=
3794 1490196134.48536: transferring module to remote "` echo ~/.ansible/tmp/ansible-tmp-1490196133.9-74490097367509 `") && sleep 0'"/ios_command.py
3794 1490196134.49556: Sending initial data
3794 1490196134.49570: Sent initial data (121 bytes)
3794 1490196135.05458: stderr chunk (state=3):
>>>Connection closed
<<<
3794 1490196135.05486: stdout chunk (state=3):
>>><<<
3794 1490196135.05494: stderr chunk (state=3):
>>><<<
3794 1490196135.05695:
3794 1490196135.05701: Connection closed
3794 1490196135.31698: stderr chunk (state=2):
>>>Administratively disabled.
<<<
3794 1490196135.31742: stdout chunk (state=3):
>>><<<
3794 1490196135.31809:
3794 1490196135.31816: Administratively disabled.
3794 1490196135.31884: done running TaskExecutor() for <host>/TASK: Show router version
3794 1490196135.31897: sending task result
3794 1490196135.31975: done sending task result
3794 1490196135.31984: WORKER PROCESS EXITING
3448 1490196135.32117: in VariableManager get_vars()
3448 1490196135.32202: done with get_vars()
3448 1490196135.32224: marking <host> as failed
3448 1490196135.32237: marking host <host> failed, current state: HOST STATE: block=2, task=1, rescue=0, always=0, role=None, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks chil
d state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
3448 1490196135.32247:^failed state is now: HOST STATE: block=2, task=1, rescue=0, always=0, role=None, run_state=ITERATING_COMPLETE, fail_state=FAILED_TASKS, pending_setup=False, tasks child state? (None), rescue child state? (None)
, always child state? (None), did rescue? False, did start at task? False
3448 1490196135.32256: getting the next task for host <host>
3448 1490196135.32263: host <host> is done iterating, returning
fatal: [<host>]: FAILED! => {"failed": true, "msg": "failed to transfer file to \"` echo ~/.ansible/tmp/ansible-tmp-1490196133.9-74490097367509 `\") && sleep 0'\"/ios_command.py:\n\nAdministratively disabled.\
n"}
3448 1490196135.32308: no more pending results, returning what we have
3448 1490196135.32316: results queue empty
3448 1490196135.32322: checking for any_errors_fatal
3448 1490196135.32329: done checking for any_errors_fatal
3448 1490196135.32334: checking for max_fail_percentage
3448 1490196135.32339: done checking for max_fail_percentage
3448 1490196135.32344: checking to see if all hosts have failed and the running result is not ok
3448 1490196135.32349: done checking to see if all hosts have failed
3448 1490196135.32353: getting the remaining hosts for this loop
3448 1490196135.32362: done getting the remaining hosts for this loop
3448 1490196135.32401: building list of next tasks for hosts
3448 1490196135.32409: getting the next task for host <host>
3448 1490196135.32416: host <host> is done iterating, returning
3448 1490196135.32421: done building task lists
3448 1490196135.32426: counting tasks in each state of execution
3448 1490196135.32431: done counting tasks in each state of execution:
num_setups: 0
num_tasks: 0
num_rescue: 0
num_always: 0
3448 1490196135.32436: all hosts are done, so returning None's for all hosts
3448 1490196135.32441: done queuing things up, now waiting for results queue to drain
3448 1490196135.32447: results queue empty
3448 1490196135.32452: checking for any_errors_fatal
3448 1490196135.32457: done checking for any_errors_fatal
3448 1490196135.32461: checking for max_fail_percentage
3448 1490196135.32466: done checking for max_fail_percentage
3448 1490196135.32470: checking to see if all hosts have failed and the running result is not ok
3448 1490196135.32478: done checking to see if all hosts have failed
3448 1490196135.32488: getting the next task for host <host>
3448 1490196135.32495: host <host> is done iterating, returning
3448 1490196135.32502: running handlers
to retry, use: --limit @/etc/ansible/poc.retry
PLAY RECAP *********************************************************************
<host> : ok=0 changed=0 unreachable=0 failed=1
Sie sollten 'local' Verbindung und' provider' Parameter verwenden, um eine Verbindung zu Routern herzustellen. Siehe die Dokumentation des Moduls und zugehörige Artikel ([Beispiel] (https://www.netnea.com/cms/2016/10/16/using-ansible-to-fetch-information-from-ios-devices/)) im Internet . –
Das hat es geschafft! Danke für Ihre Hilfe! – jonatzin