Forum Discussion

smandru_360193's avatar
smandru_360193
Icon for Nimbostratus rankNimbostratus
May 21, 2018

Run Ansible Playbook based on the Redundancy State.

We have two nodes in our PRODUCTION environment that are setup as active-standby pair. Generally i have to login, see the status and run the playbook manually on the device that is currently active.

 

But is there a way to make Ansible to figure our what is the active node and run Playbook on the Active node automatically?

 

Thanks in advance!

 

28 Replies

  • Do you not use a floating IP address to log into the devices ? The floating IP is associated with the active F5 and it is easier to know for sure that you are accessing the active F5. You can also try to execute a "show" command to identify the active F5, if you want to pursue that route.

     

  • You may have already figured it out based on previous comments, but for posterity, below is an example of using the failover_state bigip fact as a condition for performing a task which is hopefully what you were after. The bigip_node task in this playbook contains a when statement so it only runs when the value of the failover_state fact is HA_STATE_ACTIVE; therefore, the task runs on the active device and not the standby. As you probably know if you create sync'able objects on all devices in the DG with a playbook you'll encounter a change conflict between the DG members. This playbook avoids that.

     

    Update: Removing my example and instead pointing to:

     

    K10531487: Running Ansible tasks on the active BIG-IP in a device group

     

    Which AskF5 has published based on this Q&A. They've done this for other Q&As on DC as well.

     

    This article contains more detailed instructions for creating this playbook and you can leave feedback at the bottom of the page.

     

    • e0013192's avatar
      e0013192
      Icon for Altostratus rankAltostratus

      I get an error when running this playbook. Error is "msg": "module (bigip_facts) is missing interpreter line". I'm using the bigip_facts.py from the f5-ansible repo on github

       

    • Aaron_Booker's avatar
      Aaron_Booker
      Icon for Employee rankEmployee

      That error does not appear to be specific to F5 Ansible modules. Looks like an error that occurs when Ansible can't find the module due to a naming conflict. The following issues offer clues:

       

      similar issue 1

       

      similar issue 2

       

      Does running the playbook with high verbosity, the -vvvv flag, give you more details about the error?

       

    • e0013192's avatar
      e0013192
      Icon for Altostratus rankAltostratus

      I see what your saying but I don't understand why is doing this. It's looking for the module in "Using module file /media/sf_f5_ansible_modules/f5_playbooks/bigip_facts.yml" but this is not the module file and the directory for the module in my ansible.cfg is /media/sf_f5_ansible_modules. Can you explained why this might be happening?

       

  • adb_11155's avatar
    adb_11155
    Historic F5 Account

    You may have already figured it out based on previous comments, but for posterity, below is an example of using the failover_state bigip fact as a condition for performing a task which is hopefully what you were after. The bigip_node task in this playbook contains a when statement so it only runs when the value of the failover_state fact is HA_STATE_ACTIVE; therefore, the task runs on the active device and not the standby. As you probably know if you create sync'able objects on all devices in the DG with a playbook you'll encounter a change conflict between the DG members. This playbook avoids that.

     

    Update: Removing my example and instead pointing to:

     

    K10531487: Running Ansible tasks on the active BIG-IP in a device group

     

    Which AskF5 has published based on this Q&A. They've done this for other Q&As on DC as well.

     

    This article contains more detailed instructions for creating this playbook and you can leave feedback at the bottom of the page.

     

    • e0013192's avatar
      e0013192
      Icon for Altostratus rankAltostratus

      I get an error when running this playbook. Error is "msg": "module (bigip_facts) is missing interpreter line". I'm using the bigip_facts.py from the f5-ansible repo on github

       

    • adb_11155's avatar
      adb_11155
      Historic F5 Account

      That error does not appear to be specific to F5 Ansible modules. Looks like an error that occurs when Ansible can't find the module due to a naming conflict. The following issues offer clues:

       

      similar issue 1

       

      similar issue 2

       

      Does running the playbook with high verbosity, the -vvvv flag, give you more details about the error?

       

    • e0013192's avatar
      e0013192
      Icon for Altostratus rankAltostratus

      I see what your saying but I don't understand why is doing this. It's looking for the module in "Using module file /media/sf_f5_ansible_modules/f5_playbooks/bigip_facts.yml" but this is not the module file and the directory for the module in my ansible.cfg is /media/sf_f5_ansible_modules. Can you explained why this might be happening?