Ansible -2 – Configuration

Ansible configuration file at /etc/ansible/ansible.cfg

[defaults]

# some basic default values…

#inventory = /etc/ansible/hosts              ->   this is hosts are ansible using
#library = /usr/share/my_modules/      -> library
#module_utils = /usr/share/my_module_utils/
#remote_tmp = ~/.ansible/tmp
#local_tmp = ~/.ansible/tmp
#forks = 5
#poll_interval = 15
#sudo_user = root        -> sudo user
#ask_sudo_pass = True
#ask_pass = True
#transport = smart
#remote_port = 22
#module_lang = C
#module_set_locale = False

 

 

Advertisements

Ansible – 1- Setting up environments

We will setup the ansible workspace in AWS we need to create one  ‘ansible-host’ and two node

If you dont setup AWS vpc you can use(dev-prod) cloudformation template https://github.com/apocoder/aws/tree/master/vpc

Lets create the machines

OS: Ubuntu 16.04

connect to ‘ansible-host’ and install the ansible https://github.com/apocoder/aws/blob/master/ansible/install.sh

ubuntu@ip-200-30-136-143:~$ ansible –version
ansible 2.4.3.0

Perfect! we successfully installed the ansible!

 

 

 

 

Kubernetes -1- Getting Started

 

Install the gcloud SDK:

create an account at cloud.google.com

curl https://sdk.cloud.google.com | bash

gcloud auth login

gcloud config list project .

gcloud config set project <PROJECT ID> be carefull this is not project name

gcloud alpha projects list

gcloud beta projects list

Install K8S

sudo curl -sS https://get.k8s.io | bash

add to PATH kubernetes

re run

sudo curl -sS https://get.k8s.io | bash

gcloud components install kubectl

 

kubectl create clusterrolebinding permissive-binding \
  --clusterrole=cluster-admin \
  --user=admin \
  --user=kubelet \
  --group=system:serviceaccounts

kubectl proxy

Starting to serve on 127.0.0.1:8001

thats nice 😉

MacOsx Docker Start and Stop

docker-start:

#!/usr/bin/env bash

case $1 in
  -h|--help)
    echo $'usage: docker-start\n\nStarts Docker (Docker.app) on macOS and waits until the Docker environment is initialized.'
    exit 0
    ;;
esac
(( $# )) && { echo "ARGUMENT ERROR: Unexpected argument(s) specified. Use -h for help." >&2; exit 2; }

[[ $(uname) == 'Darwin' ]] || { echo "This function only runs on macOS." >&2; exit 2; }

echo "-- Starting Docker.app, if necessary..."

open -g -a Docker.app || exit

# Wait for the server to start up, if applicable.  
i=0
while ! docker system info &>/dev/null; do
  (( i++ == 0 )) && printf %s '-- Waiting for Docker to finish starting up...' || printf '.'
  sleep 1
done
(( i )) && printf '\n'

echo "-- Docker is ready."

docker-stop:

#!/usr/bin/env bash

case $1 in
  -h|--help)
    echo $'usage: docker-stop\n\nStops Docker (Docker.app) on macOS.'    
    exit 0
    ;;
esac
(( $# )) && { echo "ARGUMENT ERROR: Unexpected argument(s) specified. Use -h for help." >&2; exit 2; }

[[ $(uname) == 'Darwin' ]] || { echo "This function only runs on macOS." >&2; exit 2; }

echo "-- Quitting Docker.app, if running..."

osascript - <<'EOF' || exit
tell application "Docker"
  if it is running then quit it
end tell
EOF

echo "-- Docker is stopped."
echo "Caveat: Restarting it too quickly can cause errors."

Setting up Docker Private Registry

create a folder which name is docker-private-registry

then install docker compose

pip install docker-compose

then create the docker-compose.yml

registry:
image: registry
environment:
– STORAGE_PATH=/registry
volumes:
– registry-stuff:/registry
ports:
– “5000:5000”

run the compose file with

docker-compose up

then you will see the blank page when you visit http://localhost:5000

private registry is done but i found the nice ui for registry

 

How To Dockerize Jenkins

create a sample directory  with mkdir jenkinsci and create a new Dockerfile

cd jenkinsci

touch Dockerfile

 

FROM jenkins:2.0

USER root
RUN apt-get update \
&& apt-get install -y sudo \
&& rm -rf /var/lib/apt/lists/*
RUN echo “jenkins ALL=NOPASSWD: ALL” >> /etc/sudoers

USER jenkins
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt

then create a plugins.txt file for jenkins plugins

scm-api:latest
git-client:latest
git:latest
greenballs:latest

save it then build the jenkins image

sudo docker build -t jenkinsci .

now we must to run container

sudo docker run -d -v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker -p 8080:8080 jenkinsci

by the way we mapped docker socket ,binary  for running docker commands in container

this command will return container job id. Dont clear the console!

when you visit the http://localhost:8080 you will see the jenkins default login screen

 

you can find the administator password with

docker logs <job_id>

———————————————————————————————————————-

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

67120601cc394ff697b8a23e30440288


You can continue the next steps then you will see the Jenkins Home screen, then we must the test docker command with docker-test project

  • Create a Freestyle Project
  • Add shell build step then save it
  • sudo docker run hello-world

  • Run the build and look at the build logs

run the build.

 

Well, you dockerized jenkins 🙂 awesome!  In next chapter we will integrate jenkins volume