Skip to content

hmharsh/Ansible-Rampup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 

Repository files navigation

Ansible

Anyone who is interested in operating machines remotely, having basic knwledge of linux can follow these steps to learn Ansible, and perform interesting set of operations remotely.

Contents

---- Let's Start ----------------------------------------------

Introduction

Basic Implementation

Assignnments

Setup

  • Require 2 vm in same network
  • Install ansible on 1st (host vm)
  • Make sure python is available on 2nd (remote vm)
  • Setup text editor for ansible yaml (eg for vim add autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab in $HOME/.vimrc)
  • Create two users ansible_password and ansible_key in remote vm (without granting sudo access) and make sure st user is accessavle by ssh username and password, and for 2nd user ansible_key generate a new public private key private key parir and try to login here by ssh using private key

Questions

  • Write a adhoc command to gather facts of localhost using setup module and try to get specific value using filter attribute of setup module
  • Write Adhoc command to copy any file to suitable path of remote machine/vm whose IP specified in inventory present in the current directory
      1. To override values in ansible.cfg for single usecase, copy ansible.cfg to current directory, configure absolute or relative path of inventory in ansible.cfg
      . Learn to configure the connection from inventory, either connect remote machine by it's ssh username and passsweod or connect by private key of ssh account
    
  • Write a playbook to create a file in ansible on host machine (where ansible is running), which contain IP address of host machine all this in 1st play of the playbook and 2nd play should copy this file from this host machine to remote machine
1. Check ansible_connection = local // for faster connection on localhost
2. Explore remote_src option of copy module
  • Explore and use following frequently used modules from official Ansible doc
    • debug
    • set_fact
    • copy
    • synchronize
    • file
    • lineinfile
    • fetch
    • path
    • package
    • uri
    • shell/command
    • service
    • add_host
    • user/group

Manage Flow control and more

Assignnment

1. (If 2 remote vm are available) You are running ansible on host machine 'say 'A', now write a playbook to create 5 different files (named 'a', 'b', 'c', 'd', 'e') on remote machine 'say B' and copy all this files to remote machine 'say C' directly from 'B' to 'C'. 
2. Write a playbook in ansible to install httpd or nginx on remote vm, 
  generate a index.html file which will be hosted later, 
  content of this file should be IP address and hostname of the remote vm (where file will be hosted), 
  copy this file on appropriate path of remote vm and start the service, 
  edit "etc/hosts" of host to access remote server with custom name, 
  check the status code of the newly hosted webpage using URI module get request. 
3. Copy a file from single host present in inventory group called "webserver" to remaining hosts mentioned in inventory in (under all other groups) 

Way to Implement large Automation

Ansible GUI

Assignnment

  • deploy awx container and try to run playbook directly from git to any machine in local network
Explore: inventory, projects, credentials(machine and vault), template(job and workflow), Jobs(logging)

Advance

References

About

Ramp up program for bargainers to learn ansible

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published