andrewrothstein / ansible-docker

MIT License
5 stars 8 forks source link

Role prevents execution with tag filter #13

Open kiesel opened 6 years ago

kiesel commented 6 years ago

Given an Ansible playbook with multiple roles:

[...]
- hosts:
    - backend
  roles:
    - role: backend
      tags: backend
    - role: andrewrothstein.docker
      tags: docker
      docker_tls: False
[...]

If I execute the whole playbook for certain hosts, execution is successful. If I execute the same playbook with a --tag or -t filter, then this message appears:

TASK [andrewrothstein.docker : configuring package management system]
****************************************************************************
fatal: [be-01.XXXXXXXX]: FAILED! => {"msg": "'docker_installer' is undefined"}
        to retry, use: --limit @/.../ansible/playbook.retry

PLAY RECAP *****************************************************************
be-01.XXXXXXXX : ok=7    changed=0    unreachable=0    failed=1

Filtering with the docker tag (which in my example the role is indeed assigned to) leads to no error.

Expected state would be that the filtering out does not lead to this error.

andrewrothstein commented 6 years ago

The docker_installer comes from the host operating system's specific var file, e.g. RedHat.yml, within the role's var subdiretory. when u run it with --tag what does the output look like next to the task 'resolve platform specific vars'?

kiesel commented 6 years ago

I looked into it, it seems the order of execution of the tasks is not correct. This is the excerpt from the whole role:

PLAY [backend] **********************************

TASK [Gathering Facts] **********************************
ok: [be-01.XXXXXXXX]

TASK [andrewrothstein.docker : configuring package management system] **********************************

fatal: [be-01.XXXXXXXX]: FAILED! => {"msg": "'docker_installer' is undefined"}
        to retry, use: --limit @/home/dandral/dev/infra/aws/ansible/playbook.retry

When I run against the same host, without any --tag filtering:

PLAY [backend] **********************************

TASK [Gathering Facts] **********************************
ok: [be-01.XXXXXXXX]

[...]

TASK [andrewrothstein.docker : resolve platform specific vars] **********************************
ok: [be-01.XXXXXXXX] => (item=/home/dandral/dev/infra/aws/ansible/galaxy/andrewrothstein.docker/vars/Debian.yml)

TASK [andrewrothstein.docker : install OS dep pkgs...] **********************************
ok: [be-01.XXXXXXXX] => (item=apt-transport-https)
ok: [be-01.XXXXXXXX] => (item=ca-certificates)
ok: [be-01.XXXXXXXX] => (item=gnupg2)

TASK [andrewrothstein.docker : configuring package management system] **********************************
included: /home/dandral/dev/infra/aws/ansible/galaxy/andrewrothstein.docker/tasks/apt.yml for be-01.XXXXXXXX

TASK [andrewrothstein.docker : trust apt key] **********************************
ok: [be-01.XXXXXXXX]

TASK [andrewrothstein.docker : install docker.list] **********************************
ok: [be-01.XXXXXXXX]

TASK [andrewrothstein.docker : install docker-engine] **********************************
ok: [be-01.XXXXXXXX] => (item=docker-engine)