Giter Club home page Giter Club logo

ansible-challenge's Introduction

My reference guide

https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-ubuntu https://docs.ansible.com/ansible/latest/modules/list_of_cloud_modules.html

Setup GCP

Create a new project

Add a new service account to the project on the IAM & admin => Service accounts tab. Click create add name service account, grant permission to the 'compute admin'.

Create a private key the service account,on the IAM & admin => Service accounts tab. Click in create key choose the Json key type, download the private key json file, add place it in safe location acessible with ansilbe in modules next step

Create a ssh public/private key pair will be used to access GCP Instance by ansible example:

ssh-keygen -t rsa -b 4096 -C "ansible"
cat ~/.ssh/ansible.pub

Copy new public key for into the metadata in GCP steep: Compute Engine => Metadata => SSH Keys => select add item,input the public key obtained by output comand cat

Setup Ansible

My setup use ubuntu 20.

sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible

Your need install two extras package important in next step.

pip3 install requests google-auth
  • google-auth required for work modules ansible gcp

  • pip3 resquest, required for work dynamic inventory with ansible gcp

Basic Ansible Configuration

My directory ansible is located at cd /etc/ansible edit the ansible.cfg using the text editor you prefer.

My values

[defaults]
# Bypass host key checking in Ansible
host_key_checking = False
# Path your file genereted in command ssh-keygen -t rsa -b 4096 -C "ansible"
private_key_file = /home/guerlielton/.ssh/ansible
# Remote user who will accesse the instance with public key
remote_user = ansible
# Path static inventory this moment in use
inventory = /etc/ansible/hosts

I user sudo -s in next Step

Run Fist Playbook

Navigate to your install ansible directory in my case located in, cd /etc/ansible/ create new file with code yaml with of this file the repository example:

cd /etc/ansible

# nano create-instance.yaml

Atention in indention the code.

Run playbook

# ansible-playbook create-instance

Get ip address gereneted in output command playbook add ip in file hosts.

    - name: Show Details Instance
      debug:
        msg: "The instance is accessible at {{ address.address }}"

My file hosts default

[web-server]
ip output above the command playbook

Run Second Playbook

Follow the previous step to create the file.

# nano install-docker.yaml

This playbook install the docker with pre-defined, access ssh in step Setup GCP where pull image from docker hub and next run the container, my docker image contain node in version 10.

# ansible-playbook install-docker.yaml

Testing the application at the end

curl [add you ip]
Welcome To The Challenge Devops ! %

ansible-challenge's People

Contributors

guerlielton avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.