Forum Discussion
Run Ansible Playbook based on the Redundancy State.
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.
- e0013192Jul 23, 2018
Altostratus
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_BookerJul 24, 2018
Employee
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:
Does running the playbook with high verbosity, the -vvvv flag, give you more details about the error?
- e0013192Jul 24, 2018
Altostratus
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?
- e0013192Jul 24, 2018
Altostratus
ok I figured it out I had a bigip_facts.yml file in my playbooks directory. I removed that .yml file and now I get a much more involved error message.
"msg": "received exception: nonnumeric port: 'None'\ntraceback: Traceback (most recent call last):\n File \"/tmp/ansible_gnN7y2/ansible_module_bigip_facts.py\", line 1715, in main\n saved_active_folder = ()\n File \"/tmp/ansible_gnN7y2/ansible_module_bigip_facts.py\", line 139, in get_active_folder\n return self.api.System.Session.get_active_folder()\n File \"/usr/local/lib/python2.7/dist-packages/bigsuds.py\", line 379, in __getattr__\n client = self._client_creator('%s.%s' % (self._name, attr))\n File \"/usr/local/lib/python2.7/dist-packages/bigsuds.py\", line 183, in _create_client\n self._timeout,self._port)\n File \"/usr/local/lib/python2.7/dist-packages/bigsuds.py\", line 284, in get_client\n cache=cachedir, transport=transport, timeout=timeout)\n File \"/usr/local/lib/python2.7/dist-packages/suds/client.py\", line 115, in __init__\n self.wsdl = reader.open(url)\n File \"/usr/local/lib/python2.7/dist-packages/suds/reader.py\", line 150, in open\n d = self.fn(url, self.options)\n File \"/usr/local/lib/python2.7/dist-packages/suds/wsdl.py\", line 136, in __init__\n d = reader.open(url)\n File \"/usr/local/lib/python2.7/dist-packages/suds/reader.py\", line 74, in open\n d = self.download(url)\n File \"/usr/local/lib/python2.7/dist-packages/suds/reader.py\", line 92, in download\n fp = self.options.transport.open(Request(url))\n File \"/usr/local/lib/python2.7/dist-packages/suds/transport/https.py\", line 62, in open\n return HttpTransport.open(self, request)\n File \"/usr/local/lib/python2.7/dist-packages/suds/transport/http.py\", line 67, in open\n return self.u2open(u2request)\n File \"/usr/local/lib/python2.7/dist-packages/suds/transport/http.py\", line 132, in u2open\n return url.open(u2request, timeout=tm)\n File \"/usr/lib/python2.7/urllib2.py\", line 429, in open\n response = self._open(req, data)\n File \"/usr/lib/python2.7/urllib2.py\", line 447, in _open\n '_open', req)\n File \"/usr/lib/python2.7/urllib2.py\", line 407, in _call_chain\n result = func(*args)\n File \"/usr/lib/python2.7/urllib2.py\", line 1241, in https_open\n context=self._context)\n File \"/usr/lib/python2.7/urllib2.py\", line 1167, in do_open\n h = http_class(host, timeout=req.timeout, **http_conn_args)\n File \"/usr/lib/python2.7/httplib.py\", line 1243, in __init__\n source_address)\n File \"/usr/lib/python2.7/httplib.py\", line 736, in __init__\n (self.host, self.port) = self._get_hostport(host, port)\n File \"/usr/lib/python2.7/httplib.py\", line 777, in _get_hostport\n raise InvalidURL(\"nonnumeric port: '%s'\" % host[i+1:])\nInvalidURL: nonnumeric port: 'None'\n" }
- Aaron_BookerJul 24, 2018
Employee
I guess an httplib.py function received nothing as an argument for the port parameter. The default port is 443. Are you using a non-default port? Can you show me your bigip_facts task and a snippet from your hosts file showing the hosts for this playbook? Be sure to change IP addrs and hostnames and any other sensitive info to something generic.
- e0013192Jul 24, 2018
Altostratus
Playbook:
- name: Display BIG-IP details hosts: test_cli gather_facts: no connection: local
tasks: - name: get bigip facts bigip_facts: server: "{{ inventory_hostname }}" user: "admin" password: "secret" include: vlan delegate_to: localhost
HOSTS:
[test_cli] 10.1.1.1
As far as I know I'm using the default port. Port 443 for REST and 22 SSH.
- Aaron_BookerJul 24, 2018
Employee
Nothing wrong there...(except connection: local and delegate_to: localhost is redundant, but that won't cause the issue. More on that here) seems like something more under the hood. So before going any further since the f5-ansible repository is "an incubator" and "The modules in this repository may be broken due to experimentation or refactoring."
I suggest trying the stable releases that are included in Ansible itself:
/usr/lib/python2.7/dist-packages/ansible/modules/network/f5
or if they have been removed for some reason, you can download them from the ansible github repository as opposed to f5-ansible. The link goes directly to 2.5, but you can pick your ansible version from the Branch dropdown.
- e0013192Jul 24, 2018
Altostratus
Same error so it looks like its not related to the module
- e0013192Aug 06, 2018
Altostratus
I think I'm making progress but still don't understand why this is failing. I have the ipaddress.py in the module_utils/network/f5 folder and my ansible.cfg is pointing to the correct location for ipaddress.py.
ansible-playbook 2.6.1 config file = /etc/ansible/ansible.cfg configured module search path = [u'/usr/lib/python2.7/dist-packages/ansible/modules/network/f5'] ansible python module location = /usr/lib/python2.7/dist-packages/ansible executable location = /usr/bin/ansible-playbook python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0] Using /etc/ansible/ansible.cfg as config file setting up inventory plugins Parsed /etc/ansible/hosts inventory source with ini plugin Loading callback plugin skippy of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/skippy.pyc
PLAYBOOK: test_facts.yml ***************************************************************************************************************************** 1 plays in test_facts.yml
PLAY [Display BIG-IP details] ************************************************************************************************************************ META: ran handlers
TASK [Collect BIG-IP facts] ************************************************************************************************************************** task path: /media/sf_f5_ansible_modules/f5_playbooks/test_facts.yml:7 connection transport is rest ESTABLISH LOCAL CONNECTION FOR USER: root EXEC /bin/sh -c 'echo ~root && sleep 0' EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /root/.ansible/tmp/ansible-tmp-1533591284.1-1272967029064" && echo ansible-tmp-1533591284.1-1272967029064="echo /root/.ansible/tmp/ansible-tmp-1533591284.1-1272967029064" ) && sleep 0' connection transport is rest ESTABLISH LOCAL CONNECTION FOR USER: root EXEC /bin/sh -c 'echo ~root && sleep 0' EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /root/.ansible/tmp/ansible-tmp-1533591284.26-81286486328700" && echo ansible-tmp-1533591284.26-81286486328700="echo /root/.ansible/tmp/ansible-tmp-1533591284.26-81286486328700" ) && sleep 0' fatal: [10.128.229.143]: FAILED! => { "msg": "Could not find imported module support code for ('network', 'f5', 'ipaddress'). Looked for either ip_network.py or ipaddress.py" } fatal: [10.128.229.144]: FAILED! => { "msg": "Could not find imported module support code for ('network', 'f5', 'ipaddress'). Looked for either ip_network.py or ipaddress.py" }
- Aaron_BookerAug 08, 2018
Employee
I've run the playbook you posted earlier without error and I do not have ipaddress.py in the module_utils directory:
ls /usr/lib/python2.7/dist-packages/ansible/module_utils/network/f5 bigip.py bigip.pyc bigiq.py bigiq.pyc common.py common.pyc __init__.py __init__.pyc iworkflow.py iworkflow.pyc
In my testing, bigip_facts has not needed ipaddress.py as I do not have the package installed on my system at all. Did you expand the playbook?
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com