Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mosheabramov opened this issue Feb 1, 2022 · 2 comments

Comments

@mosheabramov
Copy link

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=<YOUR_API_KEY_HERE>
    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=<REGION_NAME_HERE>
    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
Copy link
Collaborator

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
Copy link

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": []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants