toast38coza / ansible-kong-module

A Module to help manage a [Kong](http://getkong.com) API Gateway
MIT License
34 stars 32 forks source link

Using config in Plugins module #2

Open marcoleary opened 8 years ago

marcoleary commented 8 years ago

Firstly, great work on the module. It's really helpful!

I'm having trouble following how I'm supposed to use the config parameter in the playbook. I've tried many different variations of syntax with no success. I want to enable the key-auth plugin with a custom key_names value — the following is how I thought it might work:

...
    - name: Add key authentication
      kong_plugin:
        kong_admin_uri: "{{kong_admin_base_url}}"
        api_name: "test"
        plugin_name: "key-auth"
        config:
            key_names: "key"
        state: present

But when I try to run this I get the following error when checking the plugin was enabled properly:

TASK [Verify key auth was added] ***********************************************
fatal: [localhost]: FAILED! => {"changed": false, "connection": "close", "content": "Cannot GET /\n", "content_length": "13", "content_type": "text/html; charset=utf-8", "date": "Mon, 24 Oct 2016 16:22:24 GMT", "failed": true, "msg": "Status code was not [401]: HTTP Error 404: Not Found", "redirected": false, "status": 404, "url": "http://gateway.app/", "via": "kong/0.9.3", "x_content_type_options": "nosniff", "x_kong_proxy_latency": "0", "x_kong_upstream_latency": "26", "x_powered_by": "Express"}

As it turns out, the plugin wasn't enabled (probably due to the syntax / data type issues with the config).

Have you got any examples of how I can use this config bit? Thanks!

marcoleary commented 8 years ago

A bit more playing around today with a packet capture revealed the problem. I was getting an error during the plugin create HTTP request {"key_names":"key_names is an unknown field"} so I changed my config to the following and it worked:

    - name: Add key authentication
      kong_plugin:
        kong_admin_uri: "{{kong_admin_base_url}}"
        api_name: "test"
        plugin_name: "key-auth"
        config:
            config.key_names: "key"
        state: present

Apparently I needed to prefix my config list with config.. Could you add this to your documentation please?