Tuesday, February 15, 2022

Day3 - ansible - class notes

 Ansible day3 - class notes

2/15/2022
Recap from 
Ansible
 - agentless
 - ssh
 - python
 - ansible
 - yaml
 - playbook -> task/handlers/vars/hosts/roles
 - Roles
Variable Scope
 - vars/default => default
 - group => env variables
 - Host =? certs
 - Extra => env type
Nested Groups as part of inventory



google
githubn ansible jenkins
- get some githun link
github.com/qf-devops/ansible-gjenkins
# git clone github.com/qf-devops/ansible-gjenkins
# cd ansible-jenkins
# vi inventory.yml
---
- hosts" "jenkins
....
Dry run
# ansible-playbook -i inventory.yml jenkins.yml --syntax-check
Dry run - test the script for errors.
# ansible-playbook -i inventory.yml jenkins.yml --check



install docker 
- find playbook where docker installation steps are available.
# cd roles/ansible-java8./tasks/
vi main.yml
name: install oracle java
  with item
 define the correct version of java here.

install jdk
openjdk-11-jdk-headless
google for 
jenkins install ubuntu ansible

https://www.drpraize.com/2020/07/install-jenkins-using-ansible-playbook_29.html
https://blog.knoldus.com/how-to-install-jenkins-using-ansible-on-ubuntu/
https://github.com/jcalazan/ansible-jenkins
https://medium.com/nerd-for-tech/installing-jenkins-using-an-ansible-playbook-2d99303a235f
https://middlewaretechnologies.in/2021/04/how-to-install-and-configure-jenkins-using-ansible-playbook.html
https://gist.github.com/seancallaway/39281aa0f2ab05b8e79d205f384d0ee2
https://www.techguru.cloud/post/automated-jenkins-installation/
# ap -i ansible-jenkins/inventory.yml jenkins.yml

# ap -i ansible-jenkins/jenkins.yml jenkins.yml -e "mygroup=jenkins"
ap -i ansible-jenins/inventory.yml jenkins.yml -e "mygroup=jenkins"
# systemctl start jenkins
# ps -ef | grep -i jenkins
how to get status of jenkins in ansible

# vi jenkins.init
[jenkins]
<private_IP>
192.168.10.20
[local]
localhost ansible_connection=local
# vi jenkins.ini
# cat jenkins.ini
# cat jenkins.yml
$ ap -i jenkin.ini jenkins.yml -e "mygroup=local"


# vi docker.yml
---
- hosts: local
  tasks:
  - name: install docker
    apt:
      name: docker.io
      state: latest
# ap -i jenkins.init docker.yml
# docker 
# ap -i kenkins.init docker.yml

Review 
Assignment:
  kubespray -> ansible playbook
Tower
What is Language construction?
if you want to handle, print data, execute multiple time, what you are going to use it?
we will use,
- contional statements => if-else/switch/case
- iterators (loops): for, while
- variables : int, char, float, or key:varlue pair
- functions/methods/blocks: block of statement, set of lines which we will reuse it: block of code/repetivive code
- list/array/dict: data handling, collection of data
- exception handling: if something goes wrong, I want to have a work around, try { catch{} statement. ignore and continue...
- Threads: seq/parallel: like executers. three jobs can run.. parallel approach.
if you want to run multiple request parallelly,
- we use threads
we control our data, request using above programming construct.

Now, lets think as an ansible point of view,
in ansible how condition is used: ansible: if
we will use when 
google
when condition in ansible
tasks:
  - name: Shut down CentOS 6 systems
    command: /sbin/shutdown -t now
    when:
      - ansible_facts['distribution'] == "CentOS"
      - ansible_facts['distribution_major_version'] == "6"
if two conditions below when are matching, the command section command will execute.
block statement:
control multiple modules
-----------------------
tasks:
  - name: Shut down CentOS 6 systems
    command: /sbin/shutdown -t now
    when:
      - ansible_facts['distribution'] == "CentOS"
      - ansible_facts['distribution_major_version'] == "6"
  yum: 
    name: tomcat
    state: latest
    when:
      - ansible_facts['distribution'] == "CentOS"
      - ansible_facts['distribution_major_version'] == "6"
  copy:
    src: abc.txt
    dest: /tmp
    when:
      - ansible_facts['distribution'] == "CentOS"
      - ansible_facts['distribution_major_version'] == "6"
this is not good since we are repeating it. 
can we use block statement:
tasks:
  block:
      - ansible_facts['distribution'] == "CentOS"
      - ansible_facts['distribution_major_version'] == "6"
   yum: 
     name: tomcat
     state: latest

---
tasks:
  block:
      - ansible_facts['distribution'] == "CentOS"
      - ansible_facts['distribution_major_version'] == "6"
   yum: 
     name: tomcat
     state: latest
-------------
  with_items:
  - tomcat
  - tree
  - jenkins
  - maven
------------
yum:
  name: "{{ item }}"
  state: latest
 with_items:
 - tomcat
 - tree
 - jenkins
 - maven
------------------
even first blocks fails, I want to execute, remaining
ignore-error: true

tasks:
  block:
  - name: shutdown centos 6 systems
    command: /sbin/shutdown -t now
    ignore-error: true
    tag: test  # identify your module, to control the execution.
  - name: shutdown centos 6 systems
  yum:
   name: "{{ item }}"
   state: latest
 with_items:
 - tomcat
 - tree
 - jenkins
 - maven
 tag: dev
- name: shutdown 6 systms
   copy:
     src: abc.txt
     dest: /tmp
  when:
      - ansible_facts['distribution'] == "CentOS"
      - ansible_facts['distribution_major_version'] == "6"
   
 
# ap -i hosts abc.yml --tags dev
ansible-playbook -i hosts abc.yml --tags dev  # only whereever matching tags, will have the command executed. perform particular module 
-------------
with 
------------


Tower => ami
awx
dashboard
execute
schedule
t2.laarge machine - vm
clone the repo
git clone https://github.com/vytec-ca/awxsetup/blob/
ap -i inventory ansetup.ml
install nagiox
github.com/qf-devops/ansible-nagios-example
ap -i hosts install/nagis.yml

kubespray 
https://kubernetes.io/docs/setup/production-environment/tools/kubespray/
https://docs.google.com/document/d/1_ZQ8XN1dfcaXkBJHPMIlZqoW4_BePbrCU_LW3yvDTAs/edit
x

No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...