forked from evolix/ansible-roles
Compare commits
6 commits
stable
...
ansible-lo
Author | SHA1 | Date | |
---|---|---|---|
Victor LABORIE | 399613c06a | ||
Victor LABORIE | 18511c6fba | ||
Victor LABORIE | ef79778190 | ||
Victor LABORIE | 83fff7a051 | ||
Victor LABORIE | 6e7d700dc3 | ||
Victor LABORIE | 7da18102f4 |
23
ansible-log/files/info.sh
Normal file
23
ansible-log/files/info.sh
Normal 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
|
47
ansible-log/tasks/main.yml
Normal file
47
ansible-log/tasks/main.yml
Normal 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
|
10
ansible-log/templates/ansible-info.j2
Normal file
10
ansible-log/templates/ansible-info.j2
Normal 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 }}
|
||||
|
Loading…
Reference in a new issue