1

I'm trying ansible test my playbook using molecule package which involves changing kernel parameter. But docker won't support changing kernel parameter. How can I do testing in this case(using molecule & docker)?

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Vishnu
  • 97
  • 1
  • 13
  • Answer is simple: using docker, you can't. You would have to use an other driver like vagrant with virtualbox for such tests. This driver is part of the core in molecule 2.x but was moved out as a plugin in molecule 3.x, is [not entirely ready](https://github.com/ansible-community/molecule/issues/2560) and is [looking for maintainers](https://github.com/ansible-community/molecule-vagrant/issues/2) – Zeitounator Mar 30 '20 at 17:09

1 Answers1

1

The docker container is just another process running in the same kernel so it is possible to do that but you would be changing the sysctl configuration for the actual host, which can be problematic.

My suggestion is to either skip the sysctl tasks (with tags: molecule-notest) if the role doesn't actually require the sysctl param to be set OR use a different driver like vagrant or EC2

If you still want to play around with making the sysctl changes. Here's how you can do it:

Update your molecule.yml adding the volumes, capabilities and privileged variables as follows:

...
platforms:
  - name: instance
    image: centos:7
    capabilities:
      - SYS_ADMIN
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
    privileged: true
...

(use at your own risk)

Filipe Felisbino
  • 2,712
  • 25
  • 26