so i have this playbook, which checking, if there are installed selected packages. nothing special there. Then i would like to send an output to my email, if everything went right etc.
--- - name: Install basic apps hosts: some hosts from inventory become: yes tasks: - name: load global variables include_vars: file: /etc/ansible/vars/global.yml name: global - name: install MC apt: name: mc state: present register: mc - debug: var: mc - name: install HTOP apt: name: htop state: present register: htop - name: install TMUX apt: name: tmux state: present register: tmux - name: install VIM apt: name: vim state: present register: vim - name: send email mail: host: "{{ global.mail_server }}" port: "{{ global.mail_port }}" subject: basic apps instalation was run by {{ ansible_user_id }} subtype: html # body: targeted server: {{ ansible_hostname }}
# stav MC - {{ mc.failed }} {{ mc.changed }}
# stav HTOP - {{ htop }}
# stav TMUX - {{ tmux }}
# stav VIM - {{ vim }} body: "{{ lookup('template', '/etc/ansible/templates/mail.j2') }}" from: adress to: adress run_once: true
simple Jinja template:
{% for host in play_hosts %} {{ host }}:
Midnight Commander
- is there anything wrong? {{ mc.failed }}
- any changes made? {{ mc.changed}}
Htop
- is there anything wrong? {{ htop.failed }}
- any changes made? {{ mc.changed}}
{% endfor %}
this is an output in my email:
host1: Midnight Commander - is there anything wrong? False - any changes made? True Htop - is there anything wrong? False - any changes made? True ________________________________________ host2: Midnight Commander - is there anything wrong? False - any changes made? True Htop - is there anything wrong? False - any changes made? True
but changes were made only on host1. If i make change at host2, there will be False everywhere. That means, variables registred from apt module are filled only from first host. What am i doing wrong here?