Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple imports of the role don't work #95

Open
till opened this issue May 16, 2021 · 2 comments
Open

Multiple imports of the role don't work #95

till opened this issue May 16, 2021 · 2 comments

Comments

@till
Copy link

till commented May 16, 2021

I am using your role currently like so:

  1. I use it it to setup the "base" system (docker, docker-py, etc.)
  2. I install docker plugins with another role
  3. I am using your role again to re-configure docker's daemon.json

This is a bit of a maybe oddity, but I found no other way to insure that first Docker gets installed, so I can use docker plugin install and only then do I reconfigure daemon.json to include the plugin. If I try to configure daemon.json right away, the initial start of dockerd fails and therefor also the plugin install. Anyhow, I am a bit stumped.

The problem:
It seems no matter what I do, it the role skips certain parts and looks like the variables from the second "invocation" of your role are set. In this case, I am relying on docker-py to be installed so I can use it in my docker plugin role. In the second run, I am trying to save some time by disabling (almost) everything but the configuration of daemon.json.

Here is an example playbook (or prepare.yml) with Molecule:

  tasks:
    - import_role:
        name: atosatto.docker-swarm
      vars:
        docker_daemon_config:
          storage-driver: vfs
        docker_py_package_version: 4.4.4
        docker_service_override: |
          [Service]
          ExecStart=
          ExecStart=/usr/bin/dockerd -H unix://
        skip_docker_compose: True
        skip_group: True
    - import_role:
        name: ansible-docker-plugin-loki
      vars:
        docker_loki_version: v1.2.0
    - import_role:
        name: atosatto.docker-swarm
      vars:
        docker_daemon_config:
          storage-driver: vfs
          log-driver: loki
        skip_cli: True
        skip_containerd: True
        skip_docker_compose: True
        skip_docker_py: True
        skip_group: True
        skip_swarm: True

During the first run, skip_docker_py is already true:

    TASK [atosatto.docker-swarm : Show env] ****************************************
    task path: /root/.cache/molecule/ansible-docker-plugin-loki/upgrade/roles/atosatto.docker-swarm/tasks/setup-python-pip.yml:2
    ok: [instance] => {
        "msg": "Show Variables:\nskip_docker_py: True, skip_docker_compose: True\n\nTest if #1\nFalse - False\n\nTest if #2\nFalse\n\nTest if #3\nTrue\n"
    }

I dumped it on a local branch: till@f8b42b6

I am not sure if this is a regression in Ansible as I haven't noticed this before and my test started failing only "recently". But here is my environment:

    ansible-playbook 2.9.7
      config file = /root/.cache/molecule/ansible-docker-plugin-loki/upgrade/ansible.cfg
      configured module search path = ['/usr/lib/python3.8/site-packages/molecule/provisioner/ansible/plugins/modules', '/root/.cache/molecule/ansible-docker-plugin-loki/upgrade/library', '/tmp/ansible-docker-plugin-loki/library', '/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
      ansible python module location = /usr/lib/python3.8/site-packages/ansible
      executable location = /usr/bin/ansible-playbook
      python version = 3.8.2 (default, Apr 13 2020, 10:20:46) [GCC 9.3.0]
    Using /root/.cache/molecule/ansible-docker-plugin-loki/upgrade/ansible.cfg as config file
    host_list declined parsing /root/.cache/molecule/ansible-docker-plugin-loki/upgrade/inventory/ansible_inventory.yml as it did not pass its verify_file() method
    script declined parsing /root/.cache/molecule/ansible-docker-plugin-loki/upgrade/inventory/ansible_inventory.yml as it did not pass its verify_file() method
    Parsed /root/.cache/molecule/ansible-docker-plugin-loki/upgrade/inventory/ansible_inventory.yml inventory source with yaml plugin
    1 plays in /tmp/ansible-docker-plugin-loki/molecule/upgrade/converge.yml

I tried adding allow_duplicates: True to my import_role statements. But to no avail. Anyhow, any thoughts? Maybe this is the wrong repository for this bug report. 🤷🏼 Any input appreciated.

@till till changed the title Multiple imports of the rule don't work Multiple imports of the role don't work May 16, 2021
till added a commit to hostwithquantum/ansible-docker-plugin-loki that referenced this issue May 18, 2021
till added a commit to hostwithquantum/ansible-docker-plugin-loki that referenced this issue May 19, 2021
till added a commit to hostwithquantum/ansible-docker-plugin-loki that referenced this issue May 20, 2021
till added a commit to hostwithquantum/ansible-docker-plugin-loki that referenced this issue May 20, 2021
* Chore: clean-up and upgrade action

 - upgrade molecule-action to 2.6.16
 - fix `make shell`
 - remove all defaults (for atosatto.docker-swarm)

* Fix: including the role multiple times did not work

Related: atosatto/ansible-dockerswarm#95

* Chore: upgrade molecule image; add debug

* Fix: docker python package on python2

See also docker/docker-py#2840 (comment)

* Chore: type-hints, refactoring

* Chore: configure flake8

Co-authored-by: Richard Wossal <richard@r-wos.org>
@juanluisbaptiste
Copy link

Have you thought on using a different role to install docker first instead of using this one ? like for example geerlingguy/ansible-role-docker. This way you can install docker first, then the plugin and lastly then run this role with skip_engine: true to disable the docker engine installation.

@till
Copy link
Author

till commented May 21, 2021

@juanluisbaptiste thanks for commenting.

We used the other role in the beginning, but it was too brittle and required way more additions. I know he's doing his best to manage a gazillion roles though, so no offence meant. :)

I really prefer using one, and I prefer to limit my exposure to random things I have to fix all around. ;)

I managed to overcome this like so:

# molecule/foo/requirements.yml
- name: atosatto.docker-swarm
- name: atosatto.docker-swarm-base
  src: https://github.com/atosatto/ansible-dockerswarm.git
  version: master

And then I use:

roles:
  - role: atosatto.docker-swarm-base
  - role: atosatto.docker-swarm

And it works.

till added a commit to hostwithquantum/ansible-docker-plugin-loki that referenced this issue May 26, 2021
* Update: use become where necessary

* tmp: only add build fix (#4)

* Chore: upgrade to 2.6.16 (#3)

* Chore: clean-up and upgrade action

 - upgrade molecule-action to 2.6.16
 - fix `make shell`
 - remove all defaults (for atosatto.docker-swarm)

* Fix: including the role multiple times did not work

Related: atosatto/ansible-dockerswarm#95

* Chore: upgrade molecule image; add debug

* Fix: docker python package on python2

See also docker/docker-py#2840 (comment)

* Chore: type-hints, refactoring

* Chore: configure flake8

Co-authored-by: Richard Wossal <richard@r-wos.org>

Co-authored-by: Richard Wossal <richard@r-wos.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants