Forum Discussion

PG0581's avatar
PG0581
Icon for Cirrus rankCirrus
Aug 02, 2018

Ansible bigip_command module

Is there a way you can ignore an error "wait_for" throws when a conditional statement hasn't been satisfied? In my play I have a task to see which LTM in the pair is active, and it fails when it hits the standby (which makes sense). But it would be nice if you could ignore this error.

Traceback (most recent call last):
  File "/tmp/ansible_yIW5Ex/ansible_module_bigip_command.py", line 691, in 
    main()
  File "/tmp/ansible_yIW5Ex/ansible_module_bigip_command.py", line 680, in main
    results = mm.exec_module()
  File "/tmp/ansible_yIW5Ex/ansible_module_bigip_command.py", line 617, in exec_module
    result = manager.exec_module()
  File "/tmp/ansible_yIW5Ex/ansible_module_bigip_command.py", line 409, in exec_module
    changed = self.execute()
  File "/tmp/ansible_yIW5Ex/ansible_module_bigip_command.py", line 498, in execute
    raise FailedConditionsError(errmsg, failed_conditions)
ansible.module_utils.network.common.parsing.FailedConditionsError: One or more conditional statements have not been satisfied.

fatal: [x.x.x.x -> localhost]: FAILED! => {
    "changed": false, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_yIW5Ex/ansible_module_bigip_command.py\", line 691, in \n    main()\n  File \"/tmp/ansible_yIW5Ex/ansible_module_bigip_command.py\", line 680, in main\n    results = mm.exec_module()\n  File \"/tmp/ansible_yIW5Ex/ansible_module_bigip_command.py\", line 617, in exec_module\n    result = manager.exec_module()\n  File \"/tmp/ansible_yIW5Ex/ansible_module_bigip_command.py\", line 409, in exec_module\n    changed = self.execute()\n  File \"/tmp/ansible_yIW5Ex/ansible_module_bigip_command.py\", line 498, in execute\n    raise FailedConditionsError(errmsg, failed_conditions)\nansible.module_utils.network.common.parsing.FailedConditionsError: One or more conditional statements have not been satisfied.\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 1

And here is the task I'm working with: (Note: the host inventory file contains 2 IPs only)

  - name : Checking which LTM is active....
    bigip_command:
      server: "{{ inventory_hostname }}"
      user: "{{ remote_username }}"
      password: "{{ remote_passwd }}"
      commands:
        - "tmsh show sys failover"
        - "tmsh list /sys management-ip  | grep -o x.x.x.x"
      wait_for:
        - result[0] contains active
      validate_certs: no
    delegate_to: localhost

1 Reply

  • I think your issue is the way you are using the

    wait_for
    parameter.

    So

    wait_for
    within the
    bigip_command
    module is not a conditional in the sense of if than then this but used more to confirm something is valid and if not they fails the tasks, so raises an error.

    From Ansible bigip_command_module regarding

    wait_for
    parameter:

    Specifies what to evaluate from the output of the command and what conditionals to apply. This argument will cause the task to wait for a particular conditional to be true before moving forward. If the conditional is not true by the configured retries, the task fails.

    You should look at Ansible Playbook Condistionals and look to do something like this:

    - name: Checking which LTM is active....
        bigip_command:
          server: "{{ inventory_hostname }}"
          user: "{{ remote_username }}"
          password: "{{ remote_passwd }}"
          validate_certs: no
          commands:
            - "tmsh show sys failover"      
        register: result
        delegate_to: localhost
    
    - name: Debug Failover State
      when: "'active' in result['stdout'][0]"
      debug: var=result
    

    Here we capture the output of the

    tmsh show sys failover
    command using
    register
    then we run another task, in this case
    debug
    with the
    when
    parameter which checks for the work 'active' in the output we registered.

    Our conditional

    when
    is part of future tasks and not the initial task.

    If you have multiple commands then each output will be different item in the 'stdout' list, e.g. first command you can get the string out put from

    result['stdout'][0]
    the second from
    result['stdout'][1]
    etc.