I wrote an Ansible role which does lots of things, it's called "common" and all Ansible hosts are using it.
The directory structure is as follows:
./common │ ├── ./common/README.md │ ├── ./common/defaults │ │ └── ./common/defaults/main.yml │ ├── ./common/handlers │ │ └── ./common/handlers/main.yml │ ├── ./common/meta │ │ └── ./common/meta/main.yml │ ├── ./common/tasks │ │ ├── ./common/tasks/base_packages.yml │ │ ├── ./common/tasks/iptables.yml │ │ ├── ./common/tasks/locale.yml │ │ ├── ./common/tasks/main.yml │ │ ├── ./common/tasks/pip.yml │ │ ├── ./common/tasks/pip_packages.yml │ │ ├── ./common/tasks/python.yml │ │ ├── ./common/tasks/python2_centos6.yml │ │ ├── ./common/tasks/python3_centos6.yml │ │ ├── ./common/tasks/repo.yml │ │ ├── ./common/tasks/selinux.yml │ │ ├── ./common/tasks/time.yml │ │ ├── ./common/tasks/vim.yml │ │ └── ./common/tasks/yum.yml │ ├── ./common/templates │ │ ├── ./common/templates/chrony.conf.j2 │ │ └── ./common/templates/ntp.conf.j2 │ ├── ./common/tests │ │ ├── ./common/tests/inventory │ │ └── ./common/tests/test.yml │ └── ./common/vars │ └── ./common/vars/main.yml main.yml looks like so:
--- # tasks file for common - name: python installation on centos 6 machines block: - import_tasks: python2_centos6.yml - import_tasks: python3_centos6.yml when: ansible_distribution_major_version == "6" - import_tasks: python.yml when: ansible_distribution_major_version == "7" - import_tasks: pip.yml - import_tasks: pip_packages.yml - import_tasks: repo.yml - import_tasks: yum.yml - import_tasks: selinux.yml - import_tasks: base_packages.yml - import_tasks: iptables.yml when: ansible_distribution_major_version == "7" #- import_tasks: time.yml - import_tasks: locale.yml - import_tasks: vim.yml The playbook that I'm currently running:
--- # local_slave_playbook_c6.yml - hosts: localhost vars: ansible_user_shell: /bin/bash gather_facts: true roles: - common - consul-client - hosts #- node-exporter - cron - jenkins-slave While I run the "common" role on a server, I want to know which imported_tasks file is currently running for debug matters. So for example, while Ansible "takes care" for the installation of base packages, I want to add "base_packages.yml" to the title of the task.
I looked through the list of Ansible special variables but couldn't find the variable that I need.
There is one special variable that looks right "{{ ansible_play_name }}" but that gives me "localhost".