Forum Discussion
Ansible bigip_command module error message
I have been having issues with BASH commands using the bigip_command module. What I see after the job is run is below. As you can see it is 100%, atleast in my case, abending tmsh -c to any command. The module says it runs bash. I have not been able to figure out how to do it yet.
"executed_commands": [
"tmsh -c \\\"netstat -rn \\\" | grep \\\"^0.0.0.0\\\" | grep -v mgmt | awk \\'{print \\$2}\\'"
]
"failed": false,
Here is what is in my playbook.
tasks:
- name: Default Gateway
bigip_command:
commands:
- netstat -rn | grep "^0.0.0.0" | grep -v mgmt | awk '{print $2}'
provider: "{{ provider }}"
register: f5_gateway_output
- debug:
var: f5_gateway_output
Mike your whitespace looks off. I pasted your playbook as printed above to yamllint.com and got errors. Try this.
---
tasks:
-
bigip_command:
commands:
- "netstat -rn | grep \"^0.0.0.0\" | grep -v mgmt | awk '{print $2}'"
provider: "{{ provider }}"
name: "Default Gateway"
register: f5_gateway_output
-
debug:
var: f5_gateway_output
- Mike_AFeb 17, 2021Nimbostratus
Zuke, even with what you pasted, I get the same response.
"executed_commands": [ "tmsh -c \\\"netstat -rn \\\" | grep \\\"^0.0.0.0\\\" | grep -v mgmt | awk \\'{print \\$2}\\'" ],
As you can see it is inserting "tmsh -c" before any command that is under the bigip_command module.
This module says it runs bash, I'm questioning how that is possible when "tmsh -c" is inserted before any command.
Have you successfully run a bash command with this bigip_command module?
- ZukeFeb 18, 2021Cirrostratus
No I haven't successfully run a bash command with this module, and the documentation on the Ansible page is ambiguous. "Run TMSH and bash commands" headline and every example shows a command that is executed in TMSH. I've tried running this playbook with two commands given, the first command being "bash" but no luck. I still get the encoding error.
https://docs.ansible.com/ansible/latest/collections/f5networks/f5_modules/bigip_command_module.html#ansible-collections-f5networks-f5-modules-bigip-command-module
FWIW I think I will use a different, non-F5 module if I'm going to use bash commands going forward.
- Mike_AFeb 18, 2021Nimbostratus
Agreed, there is very little documentation about running an actual bash command.
However, after some further testing, I was able to get my command working, but without "awk '{print $2}", its not optimal but in any event I was able to get it to run. The odd part is a single "ls", no flags, command throws an error.
I have no rhyme or reason as to why some work and some dont, I assume I'm/we are missing some fundamental piece to run bash commands.
Below is what is working for me right now, spacing is OK, it runs the play just not with the full command I want.
tasks: - name: Collect Big-IP Facts bigip_command: commands: - "netstat -rn | grep \"^0.0.0.0\" | grep -v \"eth0\\|mgmt\"" provider: "{{ provider }}" register: f5_audit_output - debug: var: f5_audit_output
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