diff --git a/playbooks/_common-setup.yml b/playbooks/_common-setup.yml index bdd493e..11566b1 100644 --- a/playbooks/_common-setup.yml +++ b/playbooks/_common-setup.yml @@ -1,5 +1,23 @@ #### TODO обе роли - пакаджесы и юзеры ---- +--- +- name: Check host connectivity + hosts: all + gather_facts: false + tasks: + - name: Ping hosts + ansible.builtin.ping: + register: ping_result + ignore_errors: true # Continue even if some hosts fail to ping + + - name: Add reachable hosts to a dynamic group + ansible.builtin.add_host: + name: "{{ item.ansible_host }}" + groups: reachable_hosts + when: ping_result.results is defined and item.ansible_facts.ping == 'pong' + loop: "{{ ping_result.results }}" + loop_control: + label: "{{ item.ansible_host }}" + - import_playbook: timezone.yml - import_playbook: packages.yml - import_playbook: resolvconf.yml diff --git a/playbooks/exporters.yml b/playbooks/exporters.yml index 18d7fe6..dbb0b8b 100644 --- a/playbooks/exporters.yml +++ b/playbooks/exporters.yml @@ -1,6 +1,6 @@ --- - name: node exporter! - hosts: all:!lxc + hosts: reachable_hosts:!lxc gather_facts: yes become: yes roles: diff --git a/playbooks/packages.yml b/playbooks/packages.yml index 0a3cdd8..b310821 100644 --- a/playbooks/packages.yml +++ b/playbooks/packages.yml @@ -1,8 +1,6 @@ --- - - - name: packages - hosts: all + hosts: reachable_hosts become: true become_method: sudo tasks: diff --git a/playbooks/resolvconf.yml b/playbooks/resolvconf.yml index 8a9b633..3eda221 100644 --- a/playbooks/resolvconf.yml +++ b/playbooks/resolvconf.yml @@ -1,6 +1,6 @@ --- - name: make resolv.conf work fine - hosts: all + hosts: reachable_hosts become: yes tasks: - name: Install the packages versions diff --git a/playbooks/software/act_runner.yml b/playbooks/software/act_runner.yml index 4fd1b65..f919b0b 100644 --- a/playbooks/software/act_runner.yml +++ b/playbooks/software/act_runner.yml @@ -1,7 +1,7 @@ --- - name: act_runner hosts: - - all + - reachable_hosts vars: act_runner_version: '0.2.13' gather_facts: yes diff --git a/playbooks/timezone.yml b/playbooks/timezone.yml index 88900bb..6689780 100644 --- a/playbooks/timezone.yml +++ b/playbooks/timezone.yml @@ -1,6 +1,6 @@ --- - name: Change timezone - hosts: all + hosts: reachable_hosts become: yes tasks: - name: Set timezone to Europe/London diff --git a/playbooks/users.yml b/playbooks/users.yml index 1ccc3b9..82dd5cd 100644 --- a/playbooks/users.yml +++ b/playbooks/users.yml @@ -1,6 +1,6 @@ --- - name: users - hosts: all + hosts: reachable_hosts become: yes tasks: - name: make-me