From 9cc641333f5e235184fbfe8db4af0eb1b61fc3ae Mon Sep 17 00:00:00 2001 From: "taha@asks2" Date: Wed, 29 May 2024 17:38:18 +0200 Subject: [PATCH] Updated pre and post tasks --- local.yml | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/local.yml b/local.yml index 447be26..ebb4f5c 100644 --- a/local.yml +++ b/local.yml @@ -3,6 +3,20 @@ - name: Configure your machine hosts: all + pre_tasks: + - name: Write a start message to the playbook log + ansible.builtin.shell: > + printf "\nStarted playbook '{{ ansible_play_name }}' execution at {{ now() }}\n" + >> ./log/{{ inventory_hostname }}.log + run_once: true + delegate_to: localhost + args: + chdir: "{{ playbook_dir }}" + become: true + become_user: "{{ local_user }}" + changed_when: true + tags: always + roles: - { role: common, become: true, tags: [ common ] } - { role: common-systools, become: true, tags: [ common ] } @@ -27,15 +41,27 @@ # - { role: qbittorrent, become: true, tags: [ qbittorrent ] } post_tasks: - # record the state (commit tag) of this playbook at time of last run - - name: Record the current commit tag of this playbook to log + - name: Log the current commit of '{{ ansible_play_name }}' playbook local_action: > - shell git log --pretty="Playbook was last committed by %cn on %cd (%H)" -1 - >> ./ansible.log + shell git log + --pretty="Playbook '{{ playbook_dir | basename }}' last commit %h %ci by %cn" -1 + >> ./log/{{ inventory_hostname }}.log + args: + chdir: "{{ playbook_dir }}" + become: true + become_user: "{{ local_user }}" + tags: always + - name: Write an end message to the playbook log + ansible.builtin.shell: > + echo "Ended playbook '{{ ansible_play_name }}' execution at {{ now() }}" + >> ./log/{{ inventory_hostname }}.log + run_once: true + delegate_to: localhost args: chdir: "{{ playbook_dir }}" become: true become_user: "{{ local_user }}" + changed_when: true tags: always