[os_port] Add allowed-address-pairs to an existing openstack server port

I want to set up nginx HA with keepalived and I’m preparing an ansible role for this purpose in an openstack environment (I’m using ansible 2). I would like to update the server port, that is already existing, to add allowed_address_pairs with a single pair (the virtual IP and the host mac address).
I have two problems:

  • How to get the port_id (to update the port with os_port). I cannot get this id in any facts.
  • How to get the information of that port in order to update only the allowed_address_pairs.

I know how to implement it in shell but it would be nice to use only ansible commands. Any hint how to achieve it?

Thanks in advance.

If you are using Ansible 2.1 you should be able to use the os_port_facts module.

Once you have the id of the port, you can use the os_port module to update the allowed_address_pairs, for example:

  • name: Update the allowed_address_pairs for the original port

local_action:

module: os_port

name: “{{ original_port_id }}”

state: present

allowed_address_pairs:

  • ip_address: “{{ ansible_default_ipv4.address }}”

  • ip_address: “{{ load_balancer_port.port.fixed_ips[0].ip_address }}”