ansible-nomad icon indicating copy to clipboard operation
ansible-nomad copied to clipboard

Unable to apply allow_caps to Docker config under nomad_plugins

Open bradleydwyer opened this issue 3 years ago • 1 comments

Was just trying to add the a capability to the Docker plugin (in my case, NET_ADMIN) and noticed that the generated client.hcl isn't accepted by Nomad on startup.

Given the Ansible YAML config of:

nomad_plugins:
  docker:
    config:
      allow_caps: ["NET_ADMIN"]

The generated HCL is (that Nomad rejects):

plugin "docker" {
    config {
        allow_caps = ['net_admin']
    }
}

Where I would have expected (and Nomad happily starts with):

plugin "docker" {
    config {
        allow_caps = ["NET_ADMIN"]
    }
}

I also tried a list format for the YAML

nomad_plugins:
  docker:
    config:
      allow_caps:
      - "NET_ADMIN"

But it had the same output.

I presume the lowercase originates from https://github.com/ansible-community/ansible-nomad/blob/a1853f1cf1051f72ca4b3fc672a56686b42efce6/templates/client.hcl.j2#L74 and I'm happy to change it, but I'm not sure why it's there in the first place, so I'm a little hesitant to just go changing it to solve my specific problem.

bradleydwyer avatar May 18 '21 01:05 bradleydwyer

As a possible fix, but not well tested:

{{ key | indent(count*width, first=True) }} = {% if value is string %}"{{ value }}"{% elif value is iterable and (value is not string and value is not mapping) -%}[{% set comma = joiner(",") %}{% for item in value %}{{ comma() }}"{{ item | string }}"{% endfor %}]{% else %}{{ value | string | lower }}{% endif %}

Replacing L74 from client.hcl.j2

Can submit a pull request if you think it's a valid fix. It seems to resolve my issue and doesn't appear to break other items I currently use in the docker config section - but I wouldn't call it well tested at all.

Pull request is #128

bradleydwyer avatar May 18 '21 04:05 bradleydwyer