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 not detected in centos, alpine, debian #74326

Closed
1 task done
cambid opened this issue Apr 17, 2021 · 3 comments · Fixed by #74349
Closed
1 task done

docker not detected in centos, alpine, debian #74326

cambid opened this issue Apr 17, 2021 · 3 comments · Fixed by #74349
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@cambid
Copy link
Contributor

cambid commented Apr 17, 2021

Summary

The facts for ansible_virtualization_type and ansible_virtualization_role are wrong if run in a dockercontainer of centos (tested with 8), alpine or debian (tested with buster). Only in an ubuntu-container (tested with focal or hirsute) are the values correct.
The problem can be reproduced with the latest stable version and the devel branch.

Issue Type

Bug Report

Component Name

setup, virtual/linux.py

Ansible Version

$ ansible --version
ansible 2.10.8
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/jfader/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.9.3 (default, Apr  8 2021, 23:35:02) [GCC 10.2.0]

Configuration

$ ansible-config dump --only-changed

no changes recorded

OS / Environment

Archlinux

Steps to Reproduce

Start up two containers. One with centos:8 and one with ubuntu:hirsute:

docker run --name centos_8 -it centos:8 /bin/bash
dnf -y install python3
docker run --name ubuntu_hirsute -it ubuntu:hirsute /bin/bash
apt-get update && apt-get install -y python3

Inventory:

ubuntu_hirsute ansible_connection=docker
centos_8 ansible_connection=docker

Playbook:

---
- hosts: centos_8,ubuntu_hirsute
  gather_facts: True
  tasks:

    - name: "output information about virtualization (type and role)"
      debug:
        var: "{{ item }}"
      loop:
        - ansible_virtualization_type
        - ansible_virtualization_role

Expected Results

TASK [output information about virtualization (type and role)] ************************************************
ok: [centos_8] => (item=ansible_virtualization_type) => {
    "ansible_loop_var": "item",
    "ansible_virtualization_type": "docker",
    "item": "ansible_virtualization_type"
}
ok: [ubuntu_hirsute] => (item=ansible_virtualization_type) => {
    "ansible_loop_var": "item",
    "ansible_virtualization_type": "docker",
    "item": "ansible_virtualization_type"
}
ok: [centos_8] => (item=ansible_virtualization_role) => {
    "ansible_loop_var": "item",
    "ansible_virtualization_role": "guest",
    "item": "ansible_virtualization_role"
}
ok: [ubuntu_hirsute] => (item=ansible_virtualization_role) => {
    "ansible_loop_var": "item",
    "ansible_virtualization_role": "guest",
    "item": "ansible_virtualization_role"
}

Actual Results

TASK [output information about virtualization (type and role)] ************************************************
ok: [centos_8] => (item=ansible_virtualization_type) => {
    "ansible_loop_var": "item",
    "ansible_virtualization_type": "NA",
    "item": "ansible_virtualization_type"
}
ok: [ubuntu_hirsute] => (item=ansible_virtualization_type) => {
    "ansible_loop_var": "item",
    "ansible_virtualization_type": "docker",
    "item": "ansible_virtualization_type"
}
ok: [centos_8] => (item=ansible_virtualization_role) => {
    "ansible_loop_var": "item",
    "ansible_virtualization_role": "NA",
    "item": "ansible_virtualization_role"
}
ok: [ubuntu_hirsute] => (item=ansible_virtualization_role) => {
    "ansible_loop_var": "item",
    "ansible_virtualization_role": "guest",
    "item": "ansible_virtualization_role"
}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented Apr 17, 2021

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 17, 2021
@ansibot
Copy link
Contributor

ansibot commented Apr 17, 2021

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@cambid
Copy link
Contributor Author

cambid commented Apr 20, 2021

Found the problem with the help of the ansible-IRC-channel and will create a PR for the problem.
The newest virt-what 1.21 uses a check for /.dockerenv and /.dockerinit: http://git.annexia.org/?p=virt-what.git;a=commitdiff;h=e2c49cda221f95cb65b1b3ac3ae15aa41d92f519

@samdoran samdoran added needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Apr 20, 2021
@ansible ansible locked and limited conversation to collaborators Nov 24, 2021
@sivel sivel removed the needs_verified This issue needs to be verified/reproduced by maintainer label Feb 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants