- name: nullify the ansible log file
local_action: copy content="" dest="{{ playbook_dir }}/logs/volmigration.log"
ignore_errors: true
run_once: True
- name: nullify the file content
local_action: copy content="" dest="{{ playbook_dir }}/logs/volcheck.txt"
ignore_errors: true
run_once: True
- name: Making the txt header information to volcheck.txt file
local_action:
module: lineinfile
path: "{{ playbook_dir }}/logs/volcheck.txt"
line: "host,python,old_path,mnt_path,new_path,map_path,csv_path"
state: present
create: yes
run_once: True
- name: Fetch the volume mounted status
shell: |-
{% if ansible_os_family == "Solaris" %}
grep -ws "{{ item.0 }}" /etc/vfstab|awk '{print $1}'
grep -ws "{{ item.0 }}" /etc/vfstab|awk '{print $3}'
grep -wls "{{ item.0 }}" /etc/vfstab
grep -wls "{{ item.0 }}" /etc/auto*|head -1|xargs grep -w "{{ item.0 }}"|awk '{print $2}'
grep -wls "{{ item.0 }}" /etc/auto*|head -1|xargs grep -w "{{ item.0 }}"|awk '{print $1}'
grep -wls "{{ item.0 }}" /etc/auto*|head -1
{%- else %}
grep -rws "{{ item.0 }}" /etc/fstab|awk '{print $1}'
grep -rws "{{ item.0 }}" /etc/fstab|awk '{print $2}'
grep -wls "{{ item.0 }}" /etc/fstab
grep -rls "{{ item.0 }}" /etc/auto*|head -1|xargs grep -w "{{ item.0 }}"|awk '{print $3}'
grep -rls "{{ item.0 }}" /etc/auto*|head -1|xargs grep -w "{{ item.0 }}"|awk '{print $1}'
grep -rwls "{{ item.0 }}" /etc/auto*|head -1
grep -rwls "{{ item.0 }}" /etc/rc*|head -1|xargs grep -w "{{ item.0 }}"|awk '{print $6}'
grep -rwls "{{ item.0 }}" /etc/rc*|head -1|xargs grep -w "{{ item.0 }}"|awk '{print $7}'
grep -rwls "{{ item.0 }}" /etc/rc*|head -1
{%- endif %}
with_together:
- "{{ var1 }}"
register: volchk
args:
warn: false
ignore_errors: true
- name: Making the final volcheck.txt file
local_action:
module: lineinfile
path: "{{ playbook_dir }}/logs/volcheck.txt"
line: |-
{% if item.stdout|length>0 %}
{{ inventory_hostname }},{{ ansible_python_interpreter }},{{ item.stdout_lines[0] }},{{ item.stdout_lines[1] }},NA,{{ item.stdout_lines[2] }},{{ item.item.0 }},
{%- else %}
{{ inventory_hostname }},{{ ansible_python_interpreter }},NA,NA,NA,NA,{{ item.item.0 }},
{%- endif %}
insertafter: EOF
state: present
create: yes
with_items: "{{ volchk.results }}"
- name: mark the entry of /etc/fstab and /etc/vfstab as fstab
replace:
path: "{{ playbook_dir }}/logs/volcheck.txt"
regexp: "{{ item.stdout_lines[2] }}"
replace: "fstab"
when: item.stdout|length>0 and (item.stdout_lines[2] | regex_search("/etc/fstab") or item.stdout_lines[2] | regex_search("/etc/vfstab"))
with_items: "{{ volchk.results }}"
delegate_to: localhost
- debug:
msg: "Final volume check file is located at {{ playbook_dir }}/logs/volcheck.txt"
delegate_to: localhost
run_once: true
- name: Send the final report email
local_action:
module: mail
host:
host10.google.com port: 25
to:
sur...@gmail.com subject: Ansible volume pre-check report
attach: "{{ playbook_dir }}/logs/volcheck.txt"
run_once: true
...