IBM-Cloud / ansible-collection-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
70 stars 73 forks source link

'ibmcloud_api_key' & 'ibmcloud_region' parameters for power instance creation #84

Open mosheabramov opened 2 years ago

mosheabramov commented 2 years ago

Hello,

I am trying to create a power instance using an Ansible playbook. In the documentation I found below steps:

  1. Export your API key to the IC_API_KEY environment variable: export IC_API_KEY= Note: Modules also support the 'ibmcloud_api_key' parameter, but it is recommended to only use this when encrypting your API key value.
  2. Export desired IBM Cloud region to the 'IC_REGION' environment variable: export IC_REGION= Note: Modules also support the 'ibmcloud_region' parameter.

My question is where exactly should I specify the 'ibmcloud_api_key' and 'ibmcloud_region' parameters (if I don’t want to set the environment variables)? I tried to put them in the vars.yml file and in the ansible.cfg file but when I run the ansible-playbook list_pi_images.yml I got the following error: TASK [ibm_pi_images_info] **** fatal: [localhost]: FAILED! => {"changed": false, "msg": "missing required arguments: ibmcloud_api_key"}

jaywcarman commented 2 years ago

Hi @mosheabramov !

First of all the example README needs to be updated! The ibmcloud_region parameter was re-named to region in 68c13f7, but the example documentation was never updated. I submitted a PR to fix this: #86

My question is where exactly should I specify the 'ibmcloud_api_key' and 'ibmcloud_region' parameters (if I don’t want to set the environment variables)?

They can be set directly as task parameters. For example:

---
  tasks:
    - ibm_pi_images_info:
        pi_cloud_instance_id: "01234567-89ab-cdef-0123-456789abcdef"
        ibmcloud_api_key: "mysupersecretibmcloudapikey"
        region: "mon"

If you want to store them in a separate vars.yml file (that can be re-used in other playbooks) you could do something like this: vars.yml:

---
pi_cloud_instance_id: "01234567-89ab-cdef-0123-456789abcdef"
ibmcloud_api_key: "mysupersecretibmcloudapikey"
region: "mon"

list_pi_images.yml:

---
- name: List Power Virtual Server Cloud Images
  hosts: localhost
  collections:
   - ibm.cloudcollection
  vars_files:
    - vars.yml

  tasks:
    - ibm_pi_images_info:
        pi_cloud_instance_id: "{{ pi_cloud_instance_id }}"
        ibmcloud_api_key: "{{ ibmcloud_api_key }}"
        region: "{{ region }}"

Since this requires writing the API key to file, you may want to consider using Ansible Vault to encrypt your ibmcloud_api_key value.

DaniPinol commented 2 years ago

Hi! i try to run this playbook and get TF errors:

"invocation": {
    "module_args": {
        "ibmcloud_api_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
        "pi_cloud_instance_id": "02c7_5fdb03ef-5008-46d4-b96a-7149d1efbc24",
        "region": "eu-de",
        "zone": null
    }
},
"msg": "",
"rc": 1,
"resource": {
    "_name": "ansible_20220325-173641",
    "_type": "ibm_pi_images",
    "target": "ibm_pi_images.ansible_20220325-173641"
},
"stderr": "\nError: iam_token and iam_refresh_token must be provided\n\n  on provider.tf line 1, in provider \"ibm\":\n   1: provider \"ibm\" {\n\n\n",
"stderr_lines": [
    "",
    "Error: iam_token and iam_refresh_token must be provided",
    "",
    "  on provider.tf line 1, in provider \"ibm\":",
    "   1: provider \"ibm\" {",
    "",
    ""
],
"stdout": "",
"stdout_lines": []