ansible-community / ansible-community/molecule-plugins

Create resource with service_account_contents, then the register return hidden selfLink.

Open
#307 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
164
Forks
113
Avg merge
4d 20h
Merged PRs (30d)
1

Description

Hello!

Please help me!
I want to use the **service_account_contents** variable and not **service_account_files** like int the sample.
I think the my role is more portable like a local build and gitHUB CI.
OR
_Could I get some advice?_

For example:

### working

create network with **service_account_file**

`- name: create a network
google.cloud.gcp_compute_network:
name: network-instance
auto_create_subnetworks: 'true'
project: "{{ gcp_node_config_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: present
register: network`

because the debug 'network' register result:

`"selfLink": "https://www.googleapis.com/compute/v1/projects/{{ hidden gcp_node_config_project }}/global/networks/network-instance"`

### not working

`- name: create a network
google.cloud.gcp_compute_network:
name: network-instance
auto_create_subnetworks: 'true'
project: "{{ gcp_node_config_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_contents: "{{ gcp_cred_content }}"
state: present
register: network`

because the debug 'network' register result:

`"selfLink": "https://www.********/compute/v1/projects/********/global/networks/network-instance"`

When I create instance, then i get error `GCP returned error: {'error': {'code': 400, 'message': \"Invalid value for field 'resource.networkInterfaces[0].network': 'https://www.********/compute/v1/projects/********/global/networks/network-instance'. The project '********' was not found.\"`

`- name: create a instance
google.cloud.gcp_compute_instance:
name: test-object
machine_type: n1-standard-1
disks:
- auto_delete: 'true'
boot: 'true'
source: "{{ disk }}"
- auto_delete: 'true'
interface: NVME
type: SCRATCH
initialize_params:
disk_type: local-ssd
labels:
environment: production
network_interfaces:
- network: "{{ network }}"
access_configs:
- name: External NAT
nat_ip: "{{ address }}"
type: ONE_TO_ONE_NAT
zone: us-central1-a
project: "{{ gcp_node_config_project }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_cred_file }}"
state: present
`

**ansible_collections**
> Collection Version
> ---------------------------------------- -------
> ansible.posix 2.0.0
> community.docker 4.5.2
> community.general 10.4.0
> community.library_inventory_filtering_v1 1.0.2
> google.cloud 1.5.1
> kubernetes.core 5.1.0

**ansible --version**
> ansible [core 2.18.3]
> config file = None
> configured module search path = ['/Users/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
> ansible python module location = /Users/user/.python/3.11-ansible/lib/python3.11/site-packages/ansible
> ansible collection location = /Users/user/.ansible/collections:/usr/share/ansible/collections
> executable location = /Users/user/.python/3.11-ansible/bin/ansible
> python version = 3.11.11 (main, Dec 3 2024, 17:20:40) [Clang 16.0.0 (clang-1600.0.26.4)] (/Users/user/.python/3.11-ansible/bin/python)
> jinja version = 3.1.6
> libyaml = True

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the two google.cloud.gcp_compute_network playbooks from the issue, comparing the registered selfLink when using service_account_file versus service_account_contents. Then trace the network value passed to google.cloud.gcp_compute_instance and determine whether the masked project identifier is actually returned. Done means the instance accepts the registered network when credentials come from service_account_contents.

Written by the indexing model from the issue text.

Assessment

Tech stack
ansible, google-cloud, python
Domain
cloud, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.