PLAY RECAP -- Status

44 views
Skip to first unread message

Tcpip

unread,
Feb 11, 2019, 11:10:19 AM2/11/19
to Ansible Project
Hi all,

I need to execute a script every time PLAY RECAP  failed=1, how can I configure my Ansible Playbook to do this?

Thanks. 

Stefan Schmid

unread,
Feb 11, 2019, 11:28:22 AM2/11/19
to Ansible Project
Check Ansible block. It has a rescue section.

ryad9...@gmail.com

unread,
Feb 11, 2019, 11:33:15 AM2/11/19
to Ansible Project
Hi Tcpip,

You must use this syntax task :

- name: my task
  shell: ./my_script
  when: my_variable == "1"

./my_script    ==>   the way of my script with a point front
my_variable can be PLAY_RECAP

tell me about this solution please.

Thank you

Tcpip

unread,
Feb 11, 2019, 2:14:29 PM2/11/19
to Ansible Project
Hello  ryad9200000,


I can this variable info at the end of my playbook so when I fails It will run the script. If I put PLAY_RECAP =="0" this will mean that the playbook finished ok ?

Thanks for your help.

Tcpip

unread,
Feb 11, 2019, 2:15:03 PM2/11/19
to Ansible Project
Hello Stefan,

I will take it a look,

thanks for your help.

Tcpip

unread,
Feb 11, 2019, 4:00:48 PM2/11/19
to Ansible Project
This is the playbook Im using for test.

---                                                                                                                                                                                                                                           
- hosts: all
  gather_facts: false
  connection: local
  vars:
   cli:
    #host: "{{ inventory_hostname}}"
    username: cisco
    password: cisco
  tasks:
 
    - name: Shutdown Interface
      ios_interface:
        name: Ethernet0/1
        enabled: False
        state: down
        provider: "{{ cli }}"
      register: first
 
    - pause:
        seconds=3
 
    - name: Startup Interface
      ios_interface:
        name: Ethernet0/1
        enabled: True
        state: up
        provider: "{{ cli }}"
 
    - name: my task
      shell: ./print.py
      when: failed  == '1'
      register: task
      tags: task
 
    - debug: var=task.stdout_lines[0]
      tags: show_task

the ./print.py is just showing the "hello" but is not working

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_62pEWK/ansible_module_ios_interface.py", line 490, in <module>
    main()
  File "/tmp/ansible_62pEWK/ansible_module_ios_interface.py", line 478, in main
    load_config(module, commands)
  File "/tmp/ansible_62pEWK/ansible_modlib.zip/ansible/module_utils/network/ios/ios.py", line 168, in load_config
  File "/tmp/ansible_62pEWK/ansible_modlib.zip/ansible/module_utils/connection.py", line 174, in __rpc__
ansible.module_utils.connection.ConnectionError: interface Ethernet0/1
                               ^
% Invalid input detected at '^' marker.

CBR1(config)#

fatal: [cbr1]: FAILED! => {
    "changed": false, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_62pEWK/ansible_module_ios_interface.py\", line 490, in <module>\n    main()\n  File \"/tmp/ansible_62pEWK/ansible_module_ios_interface.py\", line 478, in main\n    load_config(module, commands)\n  File \"/tmp/ansible_62pEWK/ansible_modlib.zip/ansible/module_utils/network/ios/ios.py\", line 168, in load_config\n  File \"/tmp/ansible_62pEWK/ansible_modlib.zip/ansible/module_utils/connection.py\", line 174, in __rpc__\nansible.module_utils.connection.ConnectionError: interface Ethernet0/1\r\n                               ^\r\n% Invalid input detected at '^' marker.\r\n\r\nCBR1(config)#\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 

Thanks. 

Jon Spriggs

unread,
Feb 12, 2019, 1:35:54 AM2/12/19
to ansible...@googlegroups.com
If you spot, in the logs, it shows that it's breaking on the "ethernet0/1", and, if I read it right that's in the "/" in that... So it's probably worth wrapping any instance of "ethernet0/1" in quotes, like I did.

Give that a whirl, and try again :)

---
Jon "The Nice Guy" Spriggs
@jontheniceguy everywhere...
https://jon.sprig.gs

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4aab0ed9-4cf5-420b-9b94-5bfc9d0f965d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tcpip

unread,
Feb 12, 2019, 6:32:58 AM2/12/19
to Ansible Project
Hello Jon

Yes I know the issue and it was intentional, what Im trying to do is to test if this works or not.

    - name: my task
      shell: ./print.py
      when: failed  == '1'
      register: task
      tags: task

Thanks. 
Reply all
Reply to author
Forward
0 new messages