-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
main.yml
42 lines (36 loc) · 1.26 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
---
# Updates $HOME/ansible.log with the date and time of latest ansible playbook run
- name: Set Log path
set_fact:
log_path: 'C:\Users\{{ ansible_user }}'
# This task doesn't actually matter, aslong as it runs and is registered. The timestamp for the registered variable is used
- name: Dummy task to get timestamp
win_command: whoami
register: date_output
# Accounts for cases where playbook executor is windows and its executing on localhost
- name: Get Latest git commit SHA (Windows Localhost)
win_command: git rev-parse HEAD
register: git_output
delegate_to: localhost
ignore_errors: yes
when:
- git_sha is not defined
- inventory_hostname == "localhost" or inventory_hostname == "127.0.0.1"
- name: Get Latest git commit SHA (Windows remote)
shell: git rev-parse HEAD
register: git_output
delegate_to: localhost
ignore_errors: yes
when:
- git_sha is not defined
- inventory_hostname != "localhost" and inventory_hostname != "127.0.0.1"
- name: Set git_output to git_sha
set_fact:
git_sha: "{{ git_output.stdout }}"
when: git_sha is not defined
- name: Update Log File
win_lineinfile:
create: yes
path: '{{ log_path }}\ansible.log'
insertafter: EOF
line: "{{ position }} {{ date_output.start }} {{ git_sha }}"