added vagrant build
This commit is contained in:
parent
2997f0252a
commit
6eabd40021
8 changed files with 240 additions and 12 deletions
79
ansible/install_keepalived.yaml
Normal file
79
ansible/install_keepalived.yaml
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
---
|
||||
- name: Install keepalived on 3-node cluster
|
||||
hosts: vm1,vm2,vm3
|
||||
become: true
|
||||
become_user: root
|
||||
serial: 1 # Ensure tasks are executed one host at a time
|
||||
|
||||
vars_files:
|
||||
- vault.yml
|
||||
- vars.yml
|
||||
|
||||
vars:
|
||||
tailscale_host: "{{ hostvars[inventory_hostname]['tailscale_host'] }}"
|
||||
|
||||
tasks:
|
||||
# - name: Debug gathered facts
|
||||
# ansible.builtin.debug:
|
||||
# var: ansible_facts
|
||||
|
||||
# - name: List all network interfaces and their IPs
|
||||
# ansible.builtin.debug:
|
||||
# msg: "{{ item.key }}: {{ item.value.ipv4 | map(attribute='address') | list }}"
|
||||
# with_dict: "{{ ansible_facts['network_interfaces'] }}"
|
||||
# when: ansible_facts['network_interfaces'] is defined
|
||||
|
||||
- name: Detect interface with the desired IP range
|
||||
ansible.builtin.set_fact:
|
||||
keepalived_interface: "{{ item.key }}"
|
||||
with_dict: "{{ ansible_facts['network_interfaces'] }}"
|
||||
when: item.value.ipv4 is defined and item.value.ipv4 | selectattr('address', 'search', '^192\\.168\\.56\\.') | list | length > 0
|
||||
register: detected_interface
|
||||
|
||||
- name: Set detected interface fact
|
||||
ansible.builtin.set_fact:
|
||||
keepalived_interface: "{{ detected_interface.ansible_facts.keepalived_interface }}"
|
||||
when: detected_interface is defined and detected_interface.ansible_facts is defined
|
||||
|
||||
- name: Fallback to default interface if no match is found
|
||||
ansible.builtin.set_fact:
|
||||
keepalived_interface: "enp0s8"
|
||||
when: keepalived_interface is not defined
|
||||
|
||||
- name: Fail if no interface is detected even after fallback
|
||||
ansible.builtin.fail:
|
||||
msg: "No interface with the desired IP range was detected, and fallback to default interface failed."
|
||||
when: keepalived_interface is not defined
|
||||
|
||||
- name: Install keepalived
|
||||
ansible.builtin.apt:
|
||||
name: keepalived
|
||||
state: present
|
||||
|
||||
- name: Configure keepalived on each node with decremented priority
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/keepalived/keepalived.conf
|
||||
content: |
|
||||
vrrp_instance VI_1 {
|
||||
state MASTER
|
||||
interface {{ keepalived_interface }}
|
||||
virtual_router_id 51
|
||||
priority {{ 100 - (groups['vms'].index(inventory_hostname)) }}
|
||||
advert_int 1
|
||||
authentication {
|
||||
auth_type PASS
|
||||
auth_pass mysecret
|
||||
}
|
||||
virtual_ipaddress {
|
||||
192.168.56.250
|
||||
}
|
||||
}
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
|
||||
- name: Enable and restart keepalived service
|
||||
ansible.builtin.systemd:
|
||||
name: keepalived
|
||||
enabled: true
|
||||
state: restarted
|
||||
36
ansible/requirements.txt
Normal file
36
ansible/requirements.txt
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
ansible==10.2.0
|
||||
ansible-compat==24.10.0
|
||||
ansible-core==2.17.2
|
||||
ansible-lint==24.12.2
|
||||
attrs==24.3.0
|
||||
black==24.10.0
|
||||
bracex==2.5.post1
|
||||
certifi==2024.7.4
|
||||
cffi==1.16.0
|
||||
charset-normalizer==3.3.2
|
||||
click==8.1.8
|
||||
cryptography==43.0.0
|
||||
filelock==3.16.1
|
||||
idna==3.7
|
||||
importlib_metadata==8.5.0
|
||||
Jinja2==3.1.4
|
||||
jsonschema==4.23.0
|
||||
jsonschema-specifications==2024.10.1
|
||||
MarkupSafe==2.1.5
|
||||
mypy-extensions==1.0.0
|
||||
packaging==24.1
|
||||
pathspec==0.12.1
|
||||
platformdirs==4.3.6
|
||||
pycparser==2.22
|
||||
PyYAML==6.0.1
|
||||
referencing==0.35.1
|
||||
requests==2.32.3
|
||||
resolvelib==1.0.1
|
||||
rpds-py==0.22.3
|
||||
ruamel.yaml==0.18.10
|
||||
ruamel.yaml.clib==0.2.12
|
||||
subprocess-tee==0.4.2
|
||||
urllib3==2.2.2
|
||||
wcmatch==10.0
|
||||
yamllint==1.35.1
|
||||
zipp==3.21.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue