Skip to content

Commit

Permalink
Role: auth:: optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
aybarsm committed Jul 28, 2024
1 parent 87c4b1b commit fa6c3d1
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 7 deletions.
15 changes: 14 additions & 1 deletion roles/auth/templates/etc/ssh/sshd_config.d/50-ansible.conf.j2
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
{{ ansible_managed | comment }}
{{ auth__sshd_config_all | aybarsm.helper.to_querystring('name', 'value', ' ', '\n', 'children', 4, ' ', true) }}

{% for main_item in auth__sshd_config_all %}
{% if 'value' in main_item %}
{{ main_item.name }} {{ main_item.value }}
{% else %}
{{ main_item.name }}
{% endif %}
{% if 'children' in main_item %}
{{ main_item.children | aybarsm.helper.to_querystring('name', 'value', ' ', '\n', 'children', 4, ' ', true) | indent(4, true) }}
{% endif %}
{% if main_item.name.startswith('Match ') %}
Match all
{% endif %}
{% endfor %}
7 changes: 7 additions & 0 deletions roles/network/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ network__role_enabled: false
network__manage_systemd: false
network__manage_interfaces: false
network__manage_sysctl: false
network__manage_hostname: false
network__manage_hosts: false

network__default: []
Expand Down Expand Up @@ -69,6 +70,12 @@ network__interfaces_change_strategy:
# No specific configuration is required for sysctl
##### END: network sysctl vars

##### BEGIN: network hostname vars
network__hostname: "{{ inventory_hostname }}"
# Consult with https://docs.ansible.com/ansible/latest/collections/ansible/builtin/hostname_module.html
# network__hostname_use: ''
##### END: network hostname vars

##### BEGIN: network hosts vars
network__hosts_file: /etc/hosts
network__hosts_template: etc/hosts.j2
Expand Down
7 changes: 7 additions & 0 deletions roles/network/tasks/hostname.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Deploy hostname configuration
become: true
ansible.builtin.hostname:
name: "{{ network__hostname }}"
use: "{{ network__hostname_use | default(omit) }}"
register: network__hostname_deploy
7 changes: 7 additions & 0 deletions roles/network/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
- network__role_enabled | default(false) | bool
- network__manage_sysctl | default(false) | bool

- name: Include hostname tasks
ansible.builtin.include_tasks:
file: hostname.yml
when:
- network__role_enabled | default(false) | bool
- network__manage_hostname | default(false) | bool

- name: Include hosts tasks
ansible.builtin.include_tasks:
file: hosts.yml
Expand Down
17 changes: 12 additions & 5 deletions roles/proxmox/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
proxmox__role_enabled: false

proxmox__manage_cluster: false
proxmox__manage_cluster_hosts: false
proxmox__manage_cluster_ssh_config: false

proxmox__cluster_name: ''
# For inventory specs, consult https://docs.ansible.com/ansible/latest/inventory_guide/intro_patterns.html for more information
# i.e. proxmox__cluster_inventory: 'proxmox:&atlanta'
proxmox__cluster_inventory: ''
# Ip addresses for the cluster links (will be automatically prioritized regarding the posisiton in the list)
# Cluster configuration
# For target inventory specs, consult https://docs.ansible.com/ansible/latest/inventory_guide/intro_patterns.html for more information
# proxmox__clusters:
# - name: 'pve-london01'
# target: 'proxmox:&london'
# - name: 'pve-atlanta01'
# target: 'proxmox:&atlanta'
proxmox__clusters: []
# Ip addresses for the cluster links for the host (will be automatically prioritized regarding the posisiton in the list)
proxmox__cluster_links: []
# If set to any integer higher than 0, cluster links will be prioritized automatically regarding the step.
# i.e. proxmox__cluster_links: ['10.0.0.2', 'fd00::2'] and proxmox__cluster_links_auto_priority_step: 10 will be prioritized as 10.0.0.2 = 20 and fd00::2 = 10
proxmox__cluster_links_auto_priority_step: 0

proxmox__ssh_port: 22

proxmox__repo_url_enterprise: https://enterprise.proxmox.com/debian
proxmox__repo_url_no_subscription: http://download.proxmox.com/debian

Expand Down
4 changes: 4 additions & 0 deletions roles/proxmox/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
ansible.builtin.include_vars: ../ansible/vars/main.yml
when: __ansible__config is undefined

- name: Include set fact tasks
ansible.builtin.include_tasks:
file: set_facts.yml

# - name: Proxmox Query
# become: true
# proxmox_query:
Expand Down
26 changes: 26 additions & 0 deletions roles/proxmox/tasks/set_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Set fact for main proxmox cluster configuration
ansible.builtin.set_fact:
__proxmox__clusters: "{{ __proxmox__clusters | default([]) + cluster_config }}"
vars:
cluster_inventory: "{{ lookup('ansible.builtin.inventory_hostnames', item) | split(',') }}"
cluster_query: "{{ __proxmox__cluster_query | replace('__MEMBERS__', ('[`' + (cluster_inventory | join('`,`')) + '`]')) }}"
cluster_config: "{{ dict(hostvars) | community.general.json_query(cluster_query) | map('combine', proxmox__clusters[config_index]) }}"
loop: "{{ proxmox__clusters | map(attribute='target') }}"
loop_control:
index_var: config_index
delegate_to: localhost
run_once: true
when:
- proxmox__clusters is defined
- proxmox__clusters | length > 0
- __proxmox__cluster_query is defined

- name: Set facts for proxmox cluster configuration
ansible.builtin.set_fact:
__proxmox__clusters: "{{ __proxmox__clusters | default([]) + cluster_config }}"
vars:
__proxmox__play: "{{ __proxmox__clusters | selectattr('host', 'equalto', inventory_hostname) | default(None) | first }}"
when:
- __proxmox__clusters | length > 0
- __proxmox__play is not None
5 changes: 4 additions & 1 deletion roles/proxmox/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ __proxmox__purpose_packages: >-
__proxmox_cluster_links: >-
{%- set proxmox_links = [] -%}
{%- if proxmox__manage_purpose_package_setup is defined and proxmox__manage_purpose_package_setup and proxmox__all.purposes is defined -%}
{%- endif -%}
{%- endif -%}
__proxmox__cluster_query: '*.{host: inventory_hostname, fqdn: ansible_facts.fqdn, hostname: ansible_facts.hostname, links: proxmox__cluster_links} |
[?not_null(links) && contains(__MEMBERS__, host)]'

0 comments on commit fa6c3d1

Please sign in to comment.