Comments (5)
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.
Hello,
It is a bit hard to know without seeing your group vars ;)
You can see more details about the implementation in
ansible-keepalived/templates/keepalived.conf.j2
Lines 117 to 124 in 0c9625b
It looks like the if
block would be templated with that. But there might be other ways, depends on your variables :)
from ansible-keepalived.
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.
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.
Can we close this?
from ansible-keepalived.
Related Issues (20)
- Weekly Digest (26 July, 2020 - 2 August, 2020)
- Weekly Digest (2 August, 2020 - 9 August, 2020)
- Role does not find variables when executing unrelated tasks HOT 2
- The role and its CI need modernization HOT 7
- SE Linux blocking loading of scripts as non root user HOT 2
- Unknown keyword 'notify_master_rx_lower_pri' HOT 7
- Use keepalived --config-test flag for keepalived > 2.0.4
- Problem with ansible 2.10.X HOT 7
- Improve visibility for ansible-keepalived on galaxy HOT 1
- (SG1) track script script_process not found, ignoring... HOT 3
- need to pin molecule-docker to version below 1.0 or fix CI
- issue in testing with debian 11 aka bullseye HOT 9
- Linting fails since ansible lint is updated HOT 2
- Add more execution granularity / idempotency HOT 14
- opt out of SELinux module compilation HOT 21
- Solution to a mis-configuration of the task "Dropping the tracking scripts" that should save you hours of debugging HOT 3
- Identical configuration does not work on ubuntu 22.04 while 20.04 works fine HOT 2
- Fix CI HOT 1
- New release HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible-keepalived.