dockeransiblemolecule

How to test ansible playbook which involves changing OS parameter such as kernel , ulimit etc using molecule?


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)?


Solution

  • 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)