Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set unicast mode #201

Open
ragpm opened this issue May 16, 2022 · 5 comments
Open

how to set unicast mode #201

ragpm opened this issue May 16, 2022 · 5 comments
Labels
help wanted People looking for help (no code change yet) no-answer No answer from original author for two weeks or more. Used to expire stale issues or PR. pending-user-answer Waiting for a user response

Comments

@ragpm
Copy link

ragpm commented May 16, 2022

Hi,

Is it possible to set a list of unicast peers using this role ? I'm reading the documentation and can not find anything about that.

Thanks.

@ragpm
Copy link
Author

ragpm commented May 16, 2022

found a way using like that:

unicast_src_ip: "{{ (groups['all'].index(inventory_hostname) == 0) | ternary(hostvars[groups['all'][0]].access_ip,hostvars[groups['all'][1]].access_ip) }}"
unicast_peers:
  - "{{ (groups['all'].index(inventory_hostname) == 0) | ternary(hostvars[groups['all'][1]].access_ip,hostvars[groups['all'][0]].access_ip) }}"

Is there anothe way to do that ?

@evrardjp
Copy link
Owner

Hello,

It is a bit hard to know without seeing your group vars ;)

You can see more details about the implementation in

{% if instance.unicast_src_ip is defined and instance.unicast_peers|length > 0 %}
unicast_src_ip {{ instance.unicast_src_ip }}
unicast_peer {
{% for peer in instance.unicast_peers %}
{{ peer }}
{% endfor %}
}
{% endif %}

It looks like the if block would be templated with that. But there might be other ways, depends on your variables :)

@evrardjp evrardjp added help wanted People looking for help (no code change yet) pending-user-answer Waiting for a user response labels May 16, 2022
@ragpm
Copy link
Author

ragpm commented May 16, 2022

exact. My group is simple:

all:
  hosts:
    hap1:
      ansible_host: 10.0.2.31
      ip: 10.0.2.31
      access_ip: 10.0.2.31
      ansible_user: ansible
    hap2:
      ansible_host: 10.0.2.32
      ip: 10.0.2.32
      access_ip: 10.0.2.32
      ansible_user: ansible

My vars:

vrrp_nic: enp0s3

keepalived_sync_groups:
  haproxy:
    instances:
      - internal

keepalived_instances:
  internal:
    interface: "{{ vrrp_nic }}"
    nopreempt: true
    state: "{{ (groups['all'].index(inventory_hostname) == 0) | ternary('MASTER','BACKUP') }}"
    virtual_router_id: 42
    priority: "{{ (groups['all']|length - groups['all'].index(inventory_hostname)) * 250 // (groups['all']|length) }}"
    vips:
      - "10.0.2.30/24 dev {{ vrrp_nic }}"
    unicast_src_ip: "{{ (groups['all'].index(inventory_hostname) == 0) | ternary(hostvars[groups['all'][0]].access_ip,hostvars[groups['all'][1]].access_ip) }}"
    unicast_peers:
      - "{{ (groups['all'].index(inventory_hostname) == 0) | ternary(hostvars[groups['all'][1]].access_ip,hostvars[groups['all'][0]].access_ip) }}"

The code I found is working for 2 servers (and i don't need more servers).

@evrardjp
Copy link
Owner

That should work indeed. I am not sure you need to define unicast_src_ip in your case (it depends on your nics). This could simplify a bit.

For the unicast_peer, there is probably another way to define the list based on all hostvars access_ip, but this should work, so don't worry :)

@evrardjp
Copy link
Owner

Can we close this?

@evrardjp evrardjp added pending-user-answer Waiting for a user response no-answer No answer from original author for two weeks or more. Used to expire stale issues or PR. and removed pending-user-answer Waiting for a user response labels Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted People looking for help (no code change yet) no-answer No answer from original author for two weeks or more. Used to expire stale issues or PR. pending-user-answer Waiting for a user response
Projects
None yet
Development

No branches or pull requests

2 participants