
A brief overview of Ansible .
How to create a playbook
Important Links Ansible installation
https://docs.ansible.com/ansible/latest/installation_guide/index.html
Google Module for Ansible Installation https://docs.ansible.com/ansible/latest/scenario_guides/guide_gce.html
Link to Cloud function Code Snippet https://docs.ansible.com/ansible/latest/collections/google/cloud/gcp_cloudfunctions_cloud_function_module.html
Here we discuss how to create a GCP instance using Ansible provided module
For most commonly used ansible module :
https://dzone.com/articles/10-easy-to-use-modules-in-ansible-1
The collection of Google provided ansible module
https://galaxy.ansible.com/google/cloud
-------PLAYBOOK--------------------
- name: Create an instance
hosts: localhost
gather_facts: no
vars:
gcp_project: valiant-hangout-310414
gcp_cred_kind: serviceaccount
gcp_cred_file: /home/admin_/valiant-hangout-310414-08d733642027.json
zone: "us-central1-a"
region: "us-central1"
tasks:
- name: create a disk
gcp_compute_disk:
name: 'disk-instance'
size_gb: 50
source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts'
zone: "{{ zone }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: disk
- name: create a address
gcp_compute_address:
name: 'address-instance'
region: "{{ region }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: address
How to create an inventory file to connect to your instances in GCP
Documentation on how to create an inventory file is given in the link below
https://docs.ansible.com/ansible/latest/scenario_guides/guide_gce.html
Also to create groups for your inventory file please go through the below link
http://matthieure.me/2018/12/31/ansible_inventory_plugin.html
In this demo, we will see how to create a simple playbook that will create 2 instances in GCP and upload an apache and an Nginx server in those instance
Github link to the code
https://github.com/rohitabraham02/ansible-1.git
In this demo we will discuss how to create roles in Ansible .
For more information about roles please do check out
https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html
GIT URL
https://github.com/rohitabraham02/ansible-role
Galaxy URL
https://galaxy.ansible.com/
This is an introductory course on how to use Ansible with Google Cloud .In this course i have used cloud shell to demonstrate all my example .
To get the best out of this course you need to have
1.A basic introduction to GCP .
2.A service account with relevent permissions
3.GCP Console along with cloud shell (if you do not wish to use cloud shell you can use any linux distro with gcloud cli installed )
4.An basic understanding of Ansible
5.Ansible Galaxy and gihub for role creation
What is Ansible ?
Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.
In this course we will be using the power of Ansible to create infrastructure in GCP
I will be covering the following topics in this course
1. A brief introduction to Ansible
2.Create an instance using Gcloud CLI
3.Create an instance using Google Module
4.Create a simple Architecture
5.Inventory system in GCP
6. Roles and creating a Role and uploading it to Ansible Galaxy and using the role in code
Also please do check out my other courses in udemy
Please do not forget to review my course and happy learning
Thanks in advance