Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devops-school/3e09ab77e38a2c570061b20e69194c75 to your computer and use it in GitHub Desktop.
Save devops-school/3e09ab77e38a2c570061b20e69194c75 to your computer and use it in GitHub Desktop.
hp-ansible-classroom-june-2019

Excercise 1 - Write a ansible module using Adhoc commands.

Install httpd server and create a file in /opt/index.html with content"

<html>
<h1> Welcome to HP Ansible class </h1>
</html>

Then, copy a file from /opt/index.html to /var/www/html

Excercise 2 - Adhoc commands for next all LABS.

https://www.devopsschool.com/blog/ansible-adhoc-commands-lab-excercise-part-1/

Excercise 3 - Write a ansible module using Adhoc commands to create a user and add him into sudoers and using regular user only run "Excercise 3" all adhoc commands to remote machine.

@nandiniabbinaholal
Copy link

playbook exercise:

  • name: create group and user
    hosts: localhost
    tasks:

    • name: create group
      group: name=deploy1 state=present
    • name: create user
      user: name=deploy-user1 group=deploy1 state=present
  • name: This sets up git
    hosts: localhost
    tasks:

    • name: intall git
      yum: name=git state=present
    • name: install wget
      yum: name=wget state=present
    • name: clone git repo
      git: repo=https://github.com/scmgalaxy/ansible-role-template dest=/src/ansible-examples separate_git_dir=/src/ansible-examples.gitstate=present
  • name: This sets up an httpd webserver
    hosts: localhost
    tasks:

    • name: Install the httpd apps
      yum: name=httpd
    • name: start the httpd service
      service: name=httpd state=started
  • name: create file and copy
    hosts: localhost
    tasks:

    • name: create file
      file: dest=/opt/index.html mode=600 state=touch
    • name: copy contents
      copy: dest=/opt/index.html content='

      Welcome to HP Ansible class

      '
    • name: copy file
      copy: src=/opt/index.html dest=/var/www/html/index.html

@prakashjawari
Copy link


  • name: Create a group
    hosts: web
    tasks:

    • name: Create a group for test-deploy
      group: name=test-deploy
  • name: Creating a User for group test-deploy
    hosts: web
    tasks:

    • name: Creating a user test for test-deploy group
      user: name=test group=test-deploy shell=/bin/bash state=present
  • name: Creating a file index.xml from user test
    hosts: web
    tasks:

    • name: Creating a index.html for testing a web service
      file: dest=/opt/index.html mode=755 state=touch
  • name: Updating a index.html
    hosts: web
    tasks:

    • name: Updating a index.htm
      lineinfile: state=present dest=/opt/index.html line='

      Welcome to HP Ansible class

      '
  • name: Copy Index file to the /var/www/html
    hosts: web
    tasks:

    • name: Copy index file to the http directory
      copy: src=/opt/index.html dest=/var/www/html
  • name: Installing git and wget
    hosts: web
    tasks:

    • name: Installing wget and git
      yum: name=wget state=present name=git state=present
  • name: Start http service on multiple machine
    hosts: web
    tasks:

    • name: starting a web
      service: name=httpd state=started
      ...

@neetesh80
Copy link

Lab4 - Playbooks


- import_playbook: user.yaml
- import_playbook: web.yaml
- import_playbook: web_contents.yaml
#- import_playbook: reboot.yaml
- import_playbook: pkg.yaml
- import_playbook: repo.yaml
-  name: Create a user and add it to the group
   hosts: web
   tasks:
     - name: Create a group
       group: name=deploy state=present
     - name: Create a user and add to group
       user: name=deploy group=deploy
-  name: Setup a web server
   hosts: web
   tasks:
     - name: Install Apache
       yum: name=httpd
     - name: Start Apache server
       service: name=httpd state=started
-  name: Write contents to a file on webserver
   hosts: web
   tasks:
     - name: Create a directory
       file: path=/var/www/html state=directory
     - name: Create a file
       file: dest=/var/www/html/index.html mode=600 state=touch
     - name: Write contents to the file
       lineinfile: dest=/var/www/html/index.html line='<html> <h1> Welcome to HP Ansible class </h1>  </html>'
-  name: Reboot the Apache server
   hosts: web
   tasks:
     - name: Restart the httpd server
       reboot:
---
-  name: Install git and wget packages
   hosts: web
   tasks:
     - name: Install git, wget packages
       yum: name=git,wget state=present
-  name: Clone the repo
   hosts: web
   tasks:
     - name: Create a temp directory to host repo
       file: path=/tmp/test state=directory
     - name: Clone the repo using url
       git: repo=https://github.com/scmgalaxy/ansible-role-template clone=yes dest=/tmp/test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment