ansible-community / ansible-community/molecule-plugins

Restricting the number of CPUs does not work with Docker and no way of passing "--cpus" flag while the creation of an instance

Open
#283 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
164
Forks
113
Avg merge
4d 20h
Merged PRs (30d)
1

Description

Hi, I am trying to setup a small number of connected containers with Docker for testing. In order to assure the same behavior on any HW, I am trying to restrict the number of CPUs for each container. And I am failing at that, while using the Docker-plugin. I have tried five ways to achieve my goal. For details see the following table and comments in the example file below.

1. passing raw argument to instance
2. setting provider options via provider_options
3. setting the argument via "cpus" in platform's details
4. setting provider options
5. passing raw arguments to provider

After the creation of the container, I would like to have
`# docker inspect headnode | grep NanoCpus`
` "NanoCpus": 1000000000,`
instead of
` "NanoCpus": 0,`

Is there any way how to, at least, pass raw arguments to the Docker? Or do I have to write my own Ansible script for managing Docker instances, as suggested [in this example](https://ansible.readthedocs.io/projects/molecule/examples/docker/)?

```
- - - - OS - - - -
PRETTY_NAME="Ubuntu 22.04.4 LTS"

- - - Molecule - - -
molecule 24.6.0 using python 3.10
ansible:2.17.0
default:24.6.0 from molecule
docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
```

molecule.yml
```
---
dependency:
name: galaxy

driver:
name: docker

platforms:
- name: headnode
image: docker.io/geerlingguy/docker-ubuntu2204-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
docker_networks: # might be used only once
- name: molecule
ipam_config:
- subnet: 172.206.0.0/16
networks:
- name: molecule
ipv4_address: 172.206.0.10
instance_raw_config_args: # 1st
- '--cpus=1.0' # 1st
provider_options: # 2nd
cpus: "1.0" # 2nd
cpus: 1 # 3rd
providers: # 4th
- name: docker # 4th
type: docker # 4th
options: # 4th
cpus: 1 # 4th
provider_raw_config_args: # 5th
- '--cpus=1.0' # 5th

provisioner:
name: ansible

verifier:
name: ansible

...
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the configuration in molecule.yml and checking the created container with the provided docker inspect command. Trace how the Docker plugin handles instance_raw_config_args, provider_options, providers, and provider_raw_config_args; done means the container reports NanoCpus as 1000000000 when configured with --cpus=1.0.

Written by the indexing model from the issue text.

Assessment

Tech stack
ansible, docker, python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.