Extracting an IP address from a shell command's return using a regex

Hi,

I’ve been stuck on this issue for a few days and I’m still unable to make it work, even though it should be doable. Essentially, I’m doing a shell command which gives me the following return (please don’t suggest to use an ansible module for this, the ansible module and shade don’t support choosing the subnet when associating a floatingip)

  1. “stdout_lines”: [

  2. “Created a new floatingip:”,

  3. “±--------------------±-------------------------------------+”,

  4. “| Field | Value |”,

  5. “±--------------------±-------------------------------------+”,

  6. “| created_at | 2018-02-19T09:32:44Z |”,

  7. “| description | |”,

  8. “| fixed_ip_address | 10.80.16.60 |”,

  9. “| floating_ip_address | 192.168.0.1 |”,

  10. “| floating_network_id | uuid |”,

  11. “| id | uuid |”,

  12. “| port_id | uuid |”,

  13. “| project_id | uuid |”,

  14. “| revision_number | 1 |”,

  15. “| router_id | uuid |”,

  16. “| status | DOWN |”,

  17. “| tenant_id | uuid |”,

  18. “| updated_at | 2018-02-19T09:32:44Z |”,

  19. "±--------------------±-------------------------------------+

Essentially, I want to extract the floating_ip_address line. So, I’ve been using a commonly recognized regex for IP address and, right now, I’ve reached the point where I have the following line:

    • name: extract the ip line
  1. set_fact:

  2. regexcomp: “{{ rawfloating.stdout_lines | regex_search(‘floating_ip_address \| \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b’) }}”

Now ansible tells me that it’s expecting a string or buffer. I’m not sure what to do anymore. Anyone has any ideas?

rawfloating.stdout_lines is a list not a sting, you need to use rawfloating.stdout

You need to use select to go over the list and get you the 'correct
line' as it is a 'list of lines', then you can extract the info from
that line.

Or just use stdout instead of stdout_lines.