From d4e350ffcd3b339220757157894d3a7c5e05f7ca Mon Sep 17 00:00:00 2001 From: serxoz Date: Thu, 21 Sep 2023 09:30:39 +0200 Subject: [PATCH] afinando nomad para 1 servidor e 1 cliente --- nomad.yml | 2 +- .../group_vars}/all/access.yml | 0 proxmox-inv/group_vars/all/architectures.yml | 4 ++++ proxmox-inv/group_vars/nomad_node/all.yml | 3 +++ roles/nomad/defaults/main.yml | 8 +++---- roles/nomad/tasks/install_alpine_binary.yml | 6 +++-- roles/nomad/tasks/main.yml | 2 +- roles/nomad/tasks/setup_nomad_configs.yml | 5 ++++ roles/nomad/templates/nomad.hcl.j2 | 24 ++++++++++--------- 9 files changed, 34 insertions(+), 20 deletions(-) rename {group_vars => proxmox-inv/group_vars}/all/access.yml (100%) create mode 100644 proxmox-inv/group_vars/all/architectures.yml create mode 100644 proxmox-inv/group_vars/nomad_node/all.yml diff --git a/nomad.yml b/nomad.yml index 59e314f..3c69674 100644 --- a/nomad.yml +++ b/nomad.yml @@ -1,4 +1,4 @@ -- name: Instala Consul +- name: Instala Nomad hosts: nomad_node any_errors_fatal: true become: true diff --git a/group_vars/all/access.yml b/proxmox-inv/group_vars/all/access.yml similarity index 100% rename from group_vars/all/access.yml rename to proxmox-inv/group_vars/all/access.yml diff --git a/proxmox-inv/group_vars/all/architectures.yml b/proxmox-inv/group_vars/all/architectures.yml new file mode 100644 index 0000000..1d4267c --- /dev/null +++ b/proxmox-inv/group_vars/all/architectures.yml @@ -0,0 +1,4 @@ +--- +pkg_arch_map: + aarch64: arm64 + x86_64: amd64 diff --git a/proxmox-inv/group_vars/nomad_node/all.yml b/proxmox-inv/group_vars/nomad_node/all.yml new file mode 100644 index 0000000..dc1e538 --- /dev/null +++ b/proxmox-inv/group_vars/nomad_node/all.yml @@ -0,0 +1,3 @@ +--- +nomad_datacenter: tr4ck +network_cidr: 192.168.1.0/24 diff --git a/roles/nomad/defaults/main.yml b/roles/nomad/defaults/main.yml index 36abf31..6982cc4 100644 --- a/roles/nomad/defaults/main.yml +++ b/roles/nomad/defaults/main.yml @@ -2,10 +2,8 @@ nomad_version: 1.6.2 nomad_etc_dir: /etc/nomad.d nomad_data_dir: /opt/nomad -nomad_datacenter: tr4ck +nomad_datacenter: tr4ck nomad_namespaces: - admin: - name: admin - client: - name: client + - admin + - client diff --git a/roles/nomad/tasks/install_alpine_binary.yml b/roles/nomad/tasks/install_alpine_binary.yml index 2b733f7..02f68ff 100644 --- a/roles/nomad/tasks/install_alpine_binary.yml +++ b/roles/nomad/tasks/install_alpine_binary.yml @@ -15,8 +15,10 @@ name: "{{ item }}" state: present update_cache: yes - loop: - - python3-pip + loop: + - tar + - unzip + - py3-pip - nomad become: true diff --git a/roles/nomad/tasks/main.yml b/roles/nomad/tasks/main.yml index 6c7deed..8a10f80 100644 --- a/roles/nomad/tasks/main.yml +++ b/roles/nomad/tasks/main.yml @@ -28,7 +28,7 @@ cmd: nomad namespace apply -descr "{{ item }} namespace" {{ item }} changed_when: false failed_when: false - loop: "{{ nomad_namespaces }}" + loop: "{{ nomad_namespaces }}" run_once: true #- name: Setup csi plugins diff --git a/roles/nomad/tasks/setup_nomad_configs.yml b/roles/nomad/tasks/setup_nomad_configs.yml index 90d0d11..bb06ed0 100644 --- a/roles/nomad/tasks/setup_nomad_configs.yml +++ b/roles/nomad/tasks/setup_nomad_configs.yml @@ -1,4 +1,9 @@ --- +- name: clean nomad alpine distribution config + file: + state: absent + path: /etc/nomad.d/server.hcl + - name: setup nomad server/worker config ansible.builtin.template: src: "nomad.hcl.j2" diff --git a/roles/nomad/templates/nomad.hcl.j2 b/roles/nomad/templates/nomad.hcl.j2 index 8b04899..67d2191 100644 --- a/roles/nomad/templates/nomad.hcl.j2 +++ b/roles/nomad/templates/nomad.hcl.j2 @@ -1,32 +1,33 @@ datacenter = "{{ nomad_datacenter }}" data_dir = "{{ nomad_data_dir }}" -bind_addr = "{{ vm_ip }}" +bind_addr = "0.0.0.0" name = "{{ vm_name }}" -advertise { - http = "{{ vm_ip }}" - rpc = "{{ vm_ip }}" - serf = "{{ vm_ip }}" -} {% if 'admin' in group_names %} server { enabled = true - bootstrap_expect = 3 - retry_join = [{% for host in groups['admin'] %}"{{ hostvars[host]['vm_ip'] }}"{% if not loop.last %},{% endif %}{% endfor %}] + bootstrap_expect = 1 + + # uncoment retry_join if bootstrap_expect > 1 + # retry_join = [{% for host in groups['admin'] %}"{{ hostvars[host]['vm_ip'] }}"{% if not loop.last %},{% endif %}{% endfor %}] } {% endif %} + +{% if 'client' in group_names %} client { enabled = true + servers = [{% for host in groups['admin'] %}"{{ hostvars[host]['vm_ip'] }}"{% if not loop.last %},{% endif %}{% endfor %}] + host_network "public" { cidr = "{{ network_cidr }}" } - meta { - admin = {{ "1" if 'admin' in group_names else "0" }} - } } +{% endif %} + consul { address = "{{ vm_ip}}:8500" } + plugin "docker" { config { volumes { @@ -50,6 +51,7 @@ plugin "docker" { allow_privileged = true } } + telemetry { collection_interval = "1s" disable_hostname = true