How to create Molecule and test Ansible tasks

For Ansible Molecule setup the following commands needs to be executed:
1.pip install
2.virtualenv ansible(will create virtual env
for python with ansible name)

  1. cd ansible (to go to ansible folder)
  2. source bin/activate (to activate python env)
  1. pip install molecule anisble molecule[docker] docker Now, verify ansible and molecule version
  2. ansible –version
  3. molecule –version

run command :

  1. molecule init role
    -r my-ansible-molecule-role
  2. cd my-ansible-molecule-role

folder “my-ansible-molecule-role”
will have following folders
1.defaults
2.handlers
3.meta
4.molecule
5.tasks
6.vars
except molecule, all folders have main. yml

molecule folder has
1.default > task folder
2.molecule.yml
3.playbook. yml
4.Dockerfile

now, run command

  1. cd..(to go to parent folder)
    store yml files in tasks folder thatto be tested and linted by molecule

now just run command

  1. molecule test
  2. molecule destroy
  3. molecule converge

How to create Ansible roles

Ansible Role is set of directory structures and yml files

Roles help to organize set of tasks and group it

command (to create role):

Ansible-galaxy init /etc/ansible/roles/project1 –offline

now, project1 directory has 8 directories:
1.defaults
2.files
3.handlers
4.meta
5.tasks
6.templates
7.tests
8.vars

except files and templates, all other directories have main.yml file

defaults and vars carry variables. priority goes
to vars

task stores all playbook tasks grouped and maintained

Terraform Jenkins pipeline setup

Terraform Jenkins pipeline setup

Assume Jenkins server is already setup

Dowload and install terraform cli.
Note the path of terraform binary downloaded

Install Terraform plugin from Jenkins plugin Manager.

Navigate to Global tool configuration in jenkins.
in terraform section, map the terraform binary folder path

create pipeline jenkins job

write pipeline script, utilize pipeline script
generator’s option ‘Declarative Directive Generator’ for terraform scripting

utilize pipeline script generator, create different CI/CDstages like git checkout, sonar, image publish