Role for ansible logging

This commit is contained in:
Victor LABORIE 2017-07-19 18:52:17 +02:00
parent af1045d788
commit 7da18102f4
3 changed files with 37 additions and 0 deletions

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

@ -0,0 +1,11 @@
#!/bin/sh
git config --get remote.origin.url
git log --pretty="%h - %s" -3
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)
echo ""
git -C $roles_path config --get remote.origin.url
git -C $roles_path log --pretty="%h - %s" -3

View file

@ -0,0 +1,16 @@
---
- name: Template
local_action: template src=ansible-info.j2 dest=/tmp/ansible-info.log
changed_when: no
become: no
- name: Get info on local environment
local_action: script info.sh >> /tmp/ansible-info.log
changed_when: no
become: no
- name: Copy ansible-info on remote server
copy:
src: /tmp/ansible-info.log
dest: /var/log/ansible-info.log
changed_when: no

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 }}