Compare commits

...

6 commits

3 changed files with 80 additions and 0 deletions

23
ansible-log/files/info.sh Normal file
View file

@ -0,0 +1,23 @@
#!/bin/sh
ppid=$(ps -p "$$" -o ppid=)
pppid=$(ps -p "$ppid" -o ppid=)
ppppid=$(ps -p "$pppid" -o ppid=)
ps --pid "$ppppid" -o command=
echo ""
if [ -d .git ]; then
git config --get remote.origin.url
git log --pretty="%h - %s" -3
fi
ansible_cfg=$(ansible --version|grep "config file"|awk -F'=' '{print $2}'|xargs)
roles_path=$(grep "roles_path" $ansible_cfg|awk -F'=' '{print $2}'|sed "s|~|$HOME|"|xargs)
find $roles_path -type d -name .git|while read git; do
git=$(basename "$git")
echo ""
git -C $roles_path config --get remote.origin.url
git -C $roles_path log --pretty="%h - %s" -3
done

View file

@ -0,0 +1,47 @@
---
- name: Get info on local Ansible environment
local_action: "template src=ansible-info.j2 dest=/tmp/ansible-playbook-{{ ansible_date_time.epoch }}.log"
changed_when: no
check_mode: no
become: no
tags:
- always
- name: Get info on local environment with info.sh
local_action: "script info.sh >> /tmp/ansible-playbook-{{ ansible_date_time.epoch }}.log"
changed_when: no
check_mode: no
become: no
tags:
- always
- name: Create ansible log dir on remote server
file:
path: /var/log/ansible
state: directory
owner: root
group: adm
mode: "0750"
check_mode: no
tags:
- always
- name: Copy ansible-playbook log on remote server
copy:
src: "/tmp/ansible-playbook-{{ ansible_date_time.epoch }}.log"
dest: "/var/log/ansible/ansible-playbook-{{ ansible_date_time.epoch }}.log"
owner: root
group: adm
mode: "0640"
changed_when: no
check_mode: no
tags:
- always
- name: Purge local log
local_action: "file path=/tmp/ansible-playbook-{{ ansible_date_time.epoch }}.log state=absent"
changed_when: no
check_mode: no
become: no
tags:
- always

View file

@ -0,0 +1,10 @@
date: {{ ansible_date_time.iso8601 }}
inventory: {{ inventory_file }}
playbook_dir: {{ playbook_dir}}
hosts:
{{ ansible_play_hosts | to_nice_yaml }}
roles:
{{ role_names | to_nice_yaml }}