8000 GitHub - johnmicky1/gcpcustom-image: Creating a vm instance on gcp using packer and ansible
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

johnmicky1/gcpcustom-image

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Custom Ubuntu18 image with Nginx

Creating a custom ubuntu image on gcp using packer and ansible.

Steps on how to start

Before creating the custom image, install packer and ansible together with google cloud sdk

Packer installation

  1. Download packer using curl package.

$ curl -O https://releases.hashicorp.com/packer/0.12.2/packer_0.12.2_linux_amd64.zip

  1. Install unzip incase you don't have it installed.

$ sudo apt install -y unzip

  1. Unzip the downloaded packer folder.

$ sudo unzip -d /usr/local/bin packer_0.12.2_linux_amd64.zip

  1. Verify that the installation is successful by checking whether packer is available.

$ packer

Ansible installation

On ubuntu 18.04 lts

  1. First run the update command.

$ sudo apt update

  1. Install the software-properties-common package to easily manage ansible and may be other independent softwares.

$ sudo apt install software-properties-common

  1. Add Ansible PPA.

$ sudo apt-add-repository ppa:ansible/ansible

  1. Refresh the system package index by updating.

$ sudo apt update

  1. Install ansible.

$ sudo apt install ansible

Configure ansible hosts

On ubuntu 16.04 lts

  1. Add Ansible PPA.

$ sudo apt-add-repository ppa:ansible/ansible

  1. Refresh the system package index by updating.

$ sudo apt update

  1. Install ansible.

$ sudo apt install ansible

Configure ansible hosts

Install and conigure Google Cloud sdk

  1. Create environment variable for the corect distribution of the cloud sdk.

$ export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"

  1. Add the cloud sdk distribution url as a package source

$ echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

  1. Download the google cloud platform public key

$ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

  1. Update the system package index

$ sudo apt-get update

  1. Install the Cloud SDK

$ sudo apt-get install google-cloud-sdk

  1. Initialize the SDK

gcloud init

And then follow the prompted steps to complete the default configurations.

More about gcloud sdk

To use the project

  1. Make sure that the above steps are complete and then git clone the project with HTTPS

$ git clone https://github.com/Janet-Namutebi/firstcloud-instance.git

  1. Create the service account json file using the generated json file when creating a key for the service account of your cloud project. Make sure the used service account has the required privilleges.

  2. For security reasons, its recommended to hide your service account file on git and github using the .gitignore file and also create an enironment variable for your cloud project name using the command.

$ export project_id=cloud-projectname

  1. After that, run the packer build command to build the custom image.

$ packer build packerimage.json

Note

  1. packerimage.json is the name of my project packer file.

  2. The ansible_python_interpreter configuration option is set in the playbook file under vars when you are using ansible version > 2.2.0

    |var

    |ansible_python_interpreter=/usr/bin/python3

You can also set up your project using the following file structure

        |-- packerfile.json

        |-- service_account_details.json

        |-- roles

        |---- roleone

        |------ tasks

        |--------- main.yml

        |------ templates

        |--------- nginx.conf

        |---- playbookfile.yml

About

Creating a vm instance on gcp using packer and ansible

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0