Code Monkey home page Code Monkey logo

Comments (5)

ragpm avatar ragpm commented on June 19, 2024

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 ?

from ansible-keepalived.

evrardjp avatar evrardjp commented on June 19, 2024

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 :)

from ansible-keepalived.

ragpm avatar ragpm commented on June 19, 2024

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).

from ansible-keepalived.

evrardjp avatar evrardjp commented on June 19, 2024

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 :)

from ansible-keepalived.

evrardjp avatar evrardjp commented on June 19, 2024

Can we close this?

from ansible-keepalived.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.