How do I confirm the reason why the ansible task does not in running list

Viewed 824

When I execute the playbook, only one task will be displayed

playbook: test.yaml

  play #1 (lab): lab    TAGS: []
    tasks:
      Install pip       TAGS: []

And when I execute the playbook, it is indeed normal

PLAY [lab] *****************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************
ok: [my_ipaddress]

TASK [Install pip] *********************************************************************************************************************
ok: [my_ipaddress]

PLAY RECAP *****************************************************************************************************************************
my_ipaddress              : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

and in /var/log/ansible.log also look normal as same as Execution output

So the question is, do I have to do less settings? Why is there a task that is not in the execution list, or there are other debug outputs that can display more detailed output information?

here is my ansible configuration
OS version:Ubuntu 18.04.5 LTS
ansible version:

ansible 2.9.12
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/primula/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/primula/.local/lib/python3.6/site-packages/ansible
  executable location = /home/primula/.local/bin/ansible
  python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]

my playbook:

---
- hosts: lab
  roles:
    - { role: apache2, become: yes }
    - { role: pip, become: yes }

apache2 role configuration
path:/etc/ansible/roles/apache2/tasks/maim.yaml

---
  - name: Install apache2
    apt:
      name: apache2
      update_cache: yes

pip role configuration
path:/etc/ansible/roles/pip/tasks/main.yaml

---
  - name: Install pip
    apt:
      name: python-pip
      update_cache: yes

here is my ansible invotory & ansible.cfg invotory

[lab]
<ipaddress> ansible_ssh_user=<user_name> ansible_ssh_pass='<ssh_pass>'  ansible_become_user=<root_user> ansible_become=true  ansible_become_pass='<root_pass>'

ansible.cfg

[defaults]
private_key_file = /root/.ssh/id_rsa
roles_path = /etc/ansible/roles
inventory      = /etc/ansible/hosts
timeout = 10
log_path = /var/log/ansible.log
deprecation_warnings = False
strategy = debug
any_errors_fatal = True
1 Answers

The task that is not on your execution list when using ansible-playbook --list-tasks your_playbook.yml is the one related to fact gathering done by the setup module

It is an implicit automatic task that is turned on by default for all hosts in your play. If implicit, it is not reported by the above command.

You can control fact gathering at play level with the gather_facts play keyword, e.g.

---
- name: Some play without facts gathering
  hosts: my_group
  gather_facts: false

  tasks:
    - name: dummy demo task
      debug:
        msg: I am dummy task

Regarding your question about a more detailed output, you can turn on ansible(-playbook) verbose mode with the -v(vv) switch (the more vs, the more details).

Related