UpCloudLtd / upcloud-ansible

Dynamic inventory and modules for managing servers via UpCloud's API
50 stars 17 forks source link

Can't create tags with upcloud_tag using upcloud sub account #5

Closed onnimonni closed 8 years ago

onnimonni commented 8 years ago

I can create servers with upcloud directive correctly but creating tags fails for me.

I tried to create new servers with tags using server uuids like this in my playbook:

tasks:
  - name: Create upcloud servers
      upcloud:
        state: "{{ item.state | default('present') }}"
        hostname: "{{ item.hostname }}"
        title: "{{ upcloud_project_name }} {{ item.title }}"
        zone: "{{ item.zone | default('fi-hel1') }}"
        timezone: "{{ item.timezone | default('Europe/Helsinki') }}"
        plan: "{{ item.plan }}"
        storage_devices: "{{ item.storage_devices }}"
        user: "{{ upcloud_user }}"
        ssh_keys: "{{infra_admin_ssh_keys}}"

        api_user: "{{ upcloud_api_user }}"
        api_passwd: "{{ upcloud_api_passwd }}"

      with_items: upcloud_server_spec_list
      register: upcloud_servers
      tags: ['upcloud']

    - debug: msg="{{upcloud_servers.results}}"

    - name: Tag the created servers
      upcloud_tag:
        state: present
        uuid: "{{ item.server.uuid }}"
        tags: ['helsinki']

        api_user: "{{ upcloud_api_user }}"
        api_passwd: "{{ upcloud_api_passwd }}"

      with_items: "{{ upcloud_servers.results }}"

and after that failed I also tried to put tags by using hostname:

    - name: Tag the created servers
      upcloud_tag:
        state: present
        hostname: "{{ item.hostname }}"
        tags: ['helsinki']

        api_user: "{{ upcloud_api_user }}"
        api_passwd: "{{ upcloud_api_passwd }}"

      with_items: "{{ upcloud_server_spec_list }}"

upcloud_tag module fails always with this error:

=> {
    "failed": true, "item": {
    "changed": false, "invocation": {
        "module_args": {
            "api_passwd": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "api_user": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "avoid_host": null,
            "boot_order": null, "core_number": null,
            "firewall": null, "hostname": "db1.client.geniem.io",
            "ip_addresses": null, "memory_amount": null, "nic_model": null,
            "password_delivery": null, "plan": "2xCPU-2GB",
            "ssh_keys": ["ssh-rsa AAAAB3Nz...", "ssh-rsa XYXYXY...."], 
            "state": "present",
            "storage_devices": [{"os": "Ubuntu 16.04", "size": 50}],
            "timezone": "Europe/Helsinki", "title": "client DB1",
            "user": "deploy", "uuid": null, "video_model": null,
            "vnc": null, "vnc_password": null, "zone": "fi-hel1"
        },
        "module_name": "upcloud"
    },
    "item": {
        "hostname": "server.client.geniem.io", "plan": "2xCPU-2GB", "state": "present",
        "storage_devices": [{"os": "Ubuntu 16.04", "size": 50}], "tags": ["db"],
        "title": "DB1", "zone": "fi-hel1"}, "public_ip": "80.69.172.184", "server": {
            "core_number": "2", "hostname": "db1.client.geniem.io", "license": 0,
            "memory_amount": "2048", "plan": "2xCPU-2GB", "state": "started", "tags": [],
            "title": "client DB1", "uuid": "000da9f5-8135-4f4a-ada2-445926fc3945", "zone": "fi-hel1"
        }
    },
    "msg": "{u'error': {u'error_message': u'The requested action is forbidden.', u'error_code': u'ACTION_FORBIDDEN'}
}
Traceback (most recent call last):
  File \"/tmp/ansible_aTownO/ansible_module_upcloud_tag.py\", line 230, in main
    run(module, tag_manager)
  File \"/tmp/ansible_aTownO/ansible_module_upcloud_tag.py\", line 164, in run
    tag_manager.create_missing_tags(tags)
  File \"/tmp/ansible_aTownO/ansible_module_upcloud_tag.py\", line 112, in create_missing_tags
    self.manager.create_tag(given_tag)
  File \"build/bdist.macosx-10.11-x86_64/egg/upcloud_api/cloud_manager/tag_mixin.py\", line 35, in create_tag
    res = self.request(\"POST\", \"/tag\", body)
  File \"build/bdist.macosx-10.11-x86_64/egg/upcloud_api/base.py\", line 47, in request
    return self.__error_middleware(res, res_json)
  File \"build/bdist.macosx-10.11-x86_64/egg/upcloud_api/base.py\", line 67, in __error_middleware
    raise Exception(res_json)
    Exception: {u'error': {u'error_message': u'The requested action is forbidden.', u'error_code': u'ACTION_FORBIDDEN'}}
"}

I tried to do this in admin panel and it works correctly with the same user credentials.

I also tried your api: https://api.upcloud.com straight from postman and got same results as in ansible:

screen shot 2016-06-16 at 11 47 01 pm

But still basic account information works correctly through the api: https://api.upcloud.com/1.2/account returns:

{
  "account": {
    "username": "my-user-name-here"
  }
}
onnimonni commented 8 years ago

I contacted support and they told me that this is because my account is sub account and sub accounts can't create tags.

I hope that even sub accounts could create tags in the future.

elnygren commented 8 years ago

@onnimonni yes, unfortunately sub accounts can't create tags :-/

We're gonna have to wait for UpCloud to iterate this feature further. Before that the only solution is to use the main account for tagging.