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

docker_compose_v2 docker context switch fails #892

Closed
crt0r opened this issue Jun 24, 2024 · 1 comment · Fixed by #895
Closed

docker_compose_v2 docker context switch fails #892

crt0r opened this issue Jun 24, 2024 · 1 comment · Fixed by #895
Labels
bug Something isn't working docker-compose-v2 Docker Compose v2

Comments

@crt0r
Copy link

crt0r commented Jun 24, 2024

SUMMARY

The cli_context parameter of the community.docker.docker_compose_v2 module doesn't switch the Docker context for a command it executes underneath. Instead, the following error is thrown:

conflicting options: either specify --host or --context, not both

This happens despite the docker_host parameter is not explicitly set.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

docker_compose_v2

ANSIBLE VERSION
ansible [core 2.16.6]
  config file = /home/tchuchkanov/projects/personal-site/ansible.cfg
  configured module search path = ['/home/tchuchkanov/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/tchuchkanov/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 13.2.1 20240316 (Red Hat 13.2.1-7)] (/usr/bin/python3)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
# /home/tchuchkanov/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.docker 3.11.0 

# /usr/lib/python3.12/site-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 3.9.0
CONFIGURATION
CONFIG_FILE() = /home/tchuchkanov/projects/personal-site/ansible.cfg
DEFAULT_STDOUT_CALLBACK(/home/tchuchkanov/projects/personal-site/ansible.cfg) = yaml
EDITOR(env: EDITOR) = vim
OS / ENVIRONMENT

OS: Fedora Linux 39 (Workstation Edition)
Kernel: Linux 6.8.11-200.fc39.x86_64

STEPS TO REPRODUCE
  1. Create a separate Docker context on a target Linux machine. rootless, for example.
  2. Create a compose file on the target machine in a $HOME/testdir directory.
    services:
      nginx:
        image: nginx:latest
        ports: ['80:80']
        cap_drop:
        - ALL
        cap_add:
        - CHOWN
  3. Create a playbook.
    - name: Docker Debug
      hosts: all
    
      tasks:
      - name: Run NGINX
        community.docker.docker_compose_v2:
          project_src: '{{ ansible_user_dir }}/testdir'
          cli_context: rootless
  4. Run the playbook.
EXPECTED RESULTS

The playbook execution leads to a compose project being set up for a particular Docker context.

ACTUAL RESULTS

Ansible throws an error. The docker_host parameter default value is not ignored when the cli_context is provided.

<<<OUTPUT TRIMMED FOR READABILITY>>>

fatal: [default]: FAILED! => changed=false 
  cmd: /usr/bin/docker --host unix:///var/run/docker.sock --context rootless version --format '{{ json . }}'
  invocation:
    module_args:
      api_version: auto
      build: policy
      ca_path: null
      check_files_existing: true
      cli_context: rootless
      client_cert: null
      client_key: null
      definition: null
      dependencies: true
      docker_cli: null
      docker_host: unix:///var/run/docker.sock
      env_files: null
      files: null
      profiles: null
      project_name: null
      project_src: /home/vagrant/testdir
      pull: policy
      recreate: auto
      remove_images: null
      remove_orphans: false
      remove_volumes: false
      scale: null
      services: null
      state: present
      timeout: null
      tls: false
      tls_hostname: null
      validate_certs: false
      wait: false
      wait_timeout: null
  msg: 'conflicting options: either specify --host or --context, not both'
  rc: 1
  stderr: |-
    conflicting options: either specify --host or --context, not both
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>
@felixfontein
Copy link
Collaborator

#895 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docker-compose-v2 Docker Compose v2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants