Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnixPB: Add latest commit SHA to ansible.log file #2751

Merged
merged 20 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,3 @@
state: present
backup: yes
tags: hosts_file, adoptopenjdk

# This doesn't work as ansible says it can't write to the directory
# Leaving this here in case someoen can make it work in the future
#
#- name: Record playbook completion with time in /var/log/ansiblerun.log
# lineinfile:
# state: present
# create: yes
# path: /var/tmp/ansiblerun.log
# mode: 0644
# line: "{{ ansible_date_time.iso8601_basic_short }} END"
# tags: ansiblerunlog

# Version of the above that works
- name: Record playbook completion with time in /var/log/ansiblerun.log
command: echo $(date +%Y%m%dT%H%M%S) >> /var/log/ansiblerun.log
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
---
# Updates $HOME/ansible.log with the date and time of latest ansible playbook run

- name: Set variables (Linux)
- name: Set Log path
set_fact:
home_path: /home/{{ Jenkins_Username }}
user_group: "{{ Jenkins_Username }}"
when:
- ansible_distribution != "MacOSX"
- ansible_distribution != "Solaris"
log_path: /var/log

- name: Set variables (MacOS)
set_fact:
home_path: /Users/{{ Jenkins_Username }}
user_group: "staff"
when:
- ansible_distribution == "MacOSX"

- name: Set variables (Solaris)
- name: Set variables (Not MacOS)
set_fact:
home_path: /export/home/{{ Jenkins_Username }}
user_group: "{{ Jenkins_Username }}"
user_group: "root"
when:
- ansible_distribution == "Solaris"
- ansible_distribution != "MacOSX"

- name: Check if Jenkins user exists
stat:
path: "{{ home_path }}"
register: home_exists
- name: Get Latest git commit SHA
shell: git rev-parse HEAD
register: output
delegate_to: localhost
ignore_errors: yes

- name: Update Log File
lineinfile:
owner: "{{ Jenkins_Username }}"
owner: root
group: "{{ user_group }}"
create: yes
path: "{{ home_path }}/ansible.log"
path: "{{ log_path }}/ansible.log"
insertafter: EOF
line: "{{ ansible_date_time.date }} -- {{ ansible_date_time.time }}"
line: "{{ ansible_date_time.date }} {{ ansible_date_time.time }} {{ output.stdout }}"
become: yes
become_user: root
when: home_exists.stat.exists