diff --git a/bin/actions/update.py b/bin/actions/update.py index f8ac015..d0a5c24 100755 --- a/bin/actions/update.py +++ b/bin/actions/update.py @@ -262,7 +262,7 @@ def main(): "/usr/bin/env", "ansible-playbook", "-i", f"{dotfiles_path}/config/ansible/inventory.ini", - f"{dotfiles_path}/config/ansible/main.yml", + f"{dotfiles_path}/config/ansible/playbook.yml", "--extra-vars", f"hostname={hostname}", "--extra-vars", f"ansible_user={username}", "--limit", hostname, diff --git a/config/ansible/handlers/main.yml b/config/ansible/handlers/main.yml new file mode 100644 index 0000000..ea98ace --- /dev/null +++ b/config/ansible/handlers/main.yml @@ -0,0 +1,12 @@ +--- +- name: Systemctl daemon-reload + become: true + ansible.builtin.systemd: + daemon_reload: true + +- name: Restart SSH service + become: true + ansible.builtin.service: + name: ssh + state: restarted + enabled: true diff --git a/config/ansible/main.yml b/config/ansible/playbook.yml similarity index 84% rename from config/ansible/main.yml rename to config/ansible/playbook.yml index 9f325dc..0e5d2da 100644 --- a/config/ansible/main.yml +++ b/config/ansible/playbook.yml @@ -1,5 +1,8 @@ - name: Configure all hosts hosts: all + handlers: + - name: Import handler tasks + ansible.builtin.import_tasks: handlers/main.yml gather_facts: true tasks: diff --git a/config/ansible/tasks/global/openssh-server.yml b/config/ansible/tasks/global/openssh-server.yml index f97771e..96eaffe 100644 --- a/config/ansible/tasks/global/openssh-server.yml +++ b/config/ansible/tasks/global/openssh-server.yml @@ -3,6 +3,12 @@ name: openssh-server state: present +- name: Ensure SSH service is enabled and running + ansible.builtin.service: + name: ssh + state: started + enabled: true + - name: Ensure SSH server configuration is proper ansible.builtin.template: src: templates/sshd_config.j2 @@ -11,9 +17,4 @@ group: root mode: '0644' validate: '/usr/sbin/sshd -t -f %s' - -- name: Ensure SSH service is enabled and running - ansible.builtin.service: - name: ssh - state: started - enabled: true + notify: Restart SSH service