Skip to content

A Passionate Techie

keep learning, keep growing

Enter your email address to follow this blog and receive notifications of new posts by email.

Recent learnings

  • Network monitoring tools September 5, 2021
  • Network Latencies September 5, 2021
  • Linux Network Stack September 5, 2021
  • Congestion control algorithms September 5, 2021
  • TCP performance features September 5, 2021

Recent Comments

gamejudilebaran.wordpress.com's avatargamejudilebaran.word… on Chef: Roles and Environme…
Unknown's avatarWARN: Waiting for se… on OSSEC start problem due to…
Arati Kulkarni's avatararatik711 on Ansible issues
Arati Kulkarni's avatararatik711 on Chef: Roles and Environme…
situs judi's avatarsitus judi on Chef: Roles and Environme…

Archives

  • September 2021
  • August 2021
  • March 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • February 2019
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • May 2017
  • April 2017
  • March 2017
  • January 2017
  • July 2015

Categories

  • aws
  • azure
  • centos
  • cloud
  • gcp
  • java
  • javascript
  • jenkins
  • linux
  • python
  • Uncategorized

Meta

  • Create account
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

Tag: python36

Ansible dynamic inventory GCP

We will need python:

yum install python36

yum install ansible

Make sure ansible version >=2.4.0

Download gce.ini and gce.py from: https://github.com/ansible/ansible.git

Create service_account in gce:
IAM -> Service ACCounts -> add

Give it a name, give a role Project -> Owner. It will auto create “Service Account ID”.
Click on “Furnish a new private key”
Download pkcs12 file.

Edit gce.ini add the value to the following parameter

gce_service_account_email_address = <service account email id>
Here enter the email id which you can see on the service accounts dashboard in the column “Service Account ID” in front of “Compute Engine default service account”

Make sure you create a key for this user and download the pkcs12 key.

Execute the following to convert p12 to pem:

openssl pkcs12 -in test.p12 -passin pass:notasecret -nodes -nocerts | openssl rsa -out my_project.pem

In the gce.ini add:
gce_service_account_pem_file_path = my_project.pem

Here paste the project ID in the project dashboard.
gce_project_id = <project ID>

You may get the following error:
libcloud.common.google.GoogleBaseError: {‘domain’: ‘global’, ‘reason’: ‘forbidden’, ‘message’: “Required ‘compute.zones.list’ permission for ‘projects/xxxxxxx'”}

Do the following:

Billing is enabled on the project
The product name for the project is filled in
The compute API is enabled

You need to grant “Compute Engine/Compute Instance Admin” and “Project/Service Account Actor” to your service account.
You can add user specific roles in IAM and project specific API permissions in “APIs and Services”

pip install apache-libcloud==1.5.0
pip install PyCrypto

If it gives following error:
Error: gcc -pthread -fno-strict-aliasing -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong –param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong –param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.7 -c src/MD2.c -o build/temp.linux-x86_64-2.7/src/MD2.o
src/MD2.c:31:20: fatal error: Python.h: No such file or directory
#include “Python.h”
^
compilation terminated.
error: command ‘gcc’ failed with exit status 1

Then execute the following:

yum install python36-devel

Then execute:

ansible all -i gce.py -m setup

Rate this:

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
Like Loading...
Posted on February 18, 2018February 18, 2018Categories pythonTags ansible, apache, api, cloud, dynamic, gce, gcp, google, IAM, inventory, libcloud, PyCrypto, python, python27, python36, service-accountLeave a comment on Ansible dynamic inventory GCP
Blog at WordPress.com.
  • Subscribe Subscribed
    • A Passionate Techie
    • Join 108 other subscribers
    • Already have a WordPress.com account? Log in now.
  • Privacy
    • A Passionate Techie
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
%d
    Design a site like this with WordPress.com
    Get started