Followers

Ansible - Ad-hoc Command Assignment

  Create a setup of 3 ubuntu Servers where one of the servers is the Master server where Ansible is installed whereas the other 2 webservers...

 Create a setup of 3 ubuntu Servers where one of the servers is the Master server where Ansible is installed whereas the other 2 webservers are managed nodes.

Perform the below tasks by using Ansible Adhoc commands.

1. Install Apache server on  webservers using shell module

2. Stop Apache service on webservers using service module

3. Restart Apache service on webservers using  service module.

4. Uninstall Apache service using apt module

5. Run date command on webservers.

6. Create a file call app.java under /tmp/java folder

7. Add some content to app.java file.

8. Read app.java file using shell module.

9. Delete app.java file.

10. Install tree command using apt module. 

COMMENTS

BLOGGER: 17
  1. 1. ansible webservers -m shell -a "apt install apache2 -y"
    2. ansible webservers -m service -a "name=apache2 state=stopped"
    3. ansible webservers -m service -a "name=apache2 state=restarted"
    4. ansible webservers -m apt -a "name=apache2 state=absent purge=true"
    5. ansible webservers -m shell -a "date"
    6. ansible webservers -m shell -a "mkdir /tmp/java"
    ansible webservers -m shell -a "touch /tmp/java/app.java"
    7. ansible webservers -m copy -a "content='Hello World' dest=/tmp/java/app.java"
    8. ansible webservers -m shell -a "cat /tmp/java/app.java"
    9. ansible webservers -m shell -a "rm /tmp/java/app.java"
    10. ansible webservers -m apt -a "name=tree state=present"

    ReplyDelete
  2. 1. ansible webservers -m shell -a "apt install apache2 -y"
    2. ansible webservers -m service -a "name=apache2 state=stopped"
    3. ansible webservers -m service -a "name=apache2 state=restarted"
    4. ansible webservers -m service -a "name=apache2 state=absent purge=yes"
    5. ansible webservers -m shell -a "date"
    6. ansible webservers -m shell -a "mkdir /tmp/java && touch /tmp/java/app.java"
    7. ansible webservers -m shell -a "echo “add some content to app.java” >> /tmp/java/app.java"
    8. ansible webservers -m shell -a "cat /tmp/java/app.java”
    9. ansible webservers -m shell -a "rm /tmp/java/app.java”
    10. ansible webservers -m apt -a "name=tree state=present”

    ReplyDelete
  3. ans1:

    ansible all -m shell -a "apt install apache2 -y"

    ans2:ansible webservers -m service -a "name=apache2 state=stopped"

    ans3:ansible webservers -m service -a "name=apache2 state=restarted"

    ans4:ansible webservers -m apt -a "name=apache2 state=absent purge=yes"

    ans5:ansible webservers -m shell -a "$date"

    ans6:ansible all -m shell -a "touch /tmp/app.java"

    ans7:ansible all -m shell -a "echo 'whatssapp' >> /tmp/app.java"

    ans8:ansible all -m shell -a "cat /tmp/app.java"

    ans9:ansible all -m shell -a "rm /tmp/app.java"

    ans10: ansible all -m shell -a "sudo apt install tree"

    ReplyDelete
  4. Submitted: pong

    prerequisite: create the master virtual machine and child nodes

    ssh-keygen
    cat ~/.ssh/id_rsa.pub
    sudo vi /root/.ssh/authorized_keys

    sudo vi /etc/ansible/hosts #& include the following

    [dbservers]

    192.168.33.10



    [webservers]

    192.168.33.11

    192.168.33.12

    Then,

    sudo vi /etc/ansible/ansible.cfg
    Remove '#' from '#inventory = /etc/ansible/hosts'

    1.
    ansible webservers -m shell -a " apt install apache2 -y"

    2.
    ansible webservers -m service -a "name=apache2 state=started"
    ansible webservers -m service -a "name=apache2 state=stopped"

    3.
    ansible webservers -m service -a "name=apache2 state=restarted"

    4.
    ansible webservers -m apt -a "name=apache2 state=absent purge=yes"

    5.
    ansible webservers -m shell -a "date=true"

    6.
    ansible webservers,dbservers -m shell -a "touch app.java /tmp/java"

    7.
    ansible webservers,dbservers -m copy -a "content='Hello World' dest=/tmp/java/app.java"

    8.
    ansible webservers,dbservers -m shell -a "cat /tmp/java/app.java"

    9.
    ansible webservers,dbservers -m shell -a "remove app.java /tmp/java/app.java"

    10.

    ansible webservers -m apt -a "name=tree state=present"

    ReplyDelete
  5. Mikraj

    1. Install Apache server on webservers using shell module
    ansible webservers -m shell -a "apt install apache2 -y"

    2. Stop Apache service on webservers using service module
    ansible webservers -m service -a "name=apache2 state=stopped"

    3. Restart Apache service on webservers using service module.
    ansible webservers -m service -a "name=apache2 state=restarted"

    4. Uninstall Apache service using apt module
    ansible webservers -m apt -a "name=apache2 state=absent purge=yes"


    5. Run date command on webservers.
    ansible webservers -m shell -a "date"

    6. Create a file call app.java under /tmp/java folder
    ansible webservers -m shell -a "mkdir /tmp/java/"
    ansible webservers -m shell -a "touch app.java /tmp/java"

    7. Add some content to app.java file.
    ansible webservers -m shell -a "echo 'hello world' > app.java"

    8. Read app.java file using shell module.
    ansible webservers -m shell -a "cat app.java"

    9. Delete app.java file.
    ansible webservers -m shell -a "rm -ifr app.java"

    10. Install tree command using apt module.
    ansible webservers -m apt -a "name=tree state=present"

    ReplyDelete
  6. 1. Install Apache server on  webservers using shell module
    - On Master server, > ansible webservers -m shell -a "apt install apache2 -y"
    - To check, run on both managed nodes > systemctl status apache2
    - Active: active (running)

    2. Stop Apache service on webservers using service module
    - On Master server, > ansible webservers -m service -a "name=apache2 state=stopped"
    - To check, run on both managed nodes > systemctl status apache2
    - Active: inactive (dead)

    3. Restart Apache service on webservers using  service module.
    - On Master server, > ansible webservers -m service -a "name=apache2 state=reloaded"
    - To check, run on both managed nodes > systemctl status apache2
    - Active: active (running)

    4. Uninstall Apache service using apt module
    - On Master server, > ansible webservers -m apt -a "name=apache2 state=absent purge=yes"
    - To check, run on both managed nodes > systemctl status apache2
    - Unit apache2.service could not be found.

    5. Run date command on webservers.
    - On both managed nodes > date
    - Mon Feb 21 06:41:32 UTC 2022

    6. Create a file call app.java under /tmp/java folder
    - mkdir /tmp/java
    - touch /tmp/java app.java

    7. Add some content to app.java file.
    - echo "Hello there" >> /tmp/java/app.java

    8. Read app.java file using shell module.
    - ansible dbservers -m shell -a "cat /tmp/java/app.java"

    9. Delete app.java file.
    - rm /tmp/java/app.java

    10. Install tree command using apt module. 
    - ansible dbservers -m apt -a "name=tree state=present"

    ReplyDelete
  7. Asyraf

    1. Install Apache server on webservers using shell module

    ansible webservers -m shell -a " apt install apache2 -y"

    2. Stop Apache service on webservers using service module

    ansible webservers -m service -a "name=apache2 state=stopped"

    3. Restart Apache service on webservers using service module.

    ansible webservers -m service -a "name=apache2 state=stopped"

    4. Uninstall Apache service using apt module

    ansible webservers -m apt -a "name=apache2 state=absent purge=yes"

    5. Run date command on webservers.

    ansible webservers,dbservers -m shell -a "date"

    6. Create a file call app.java under /tmp/java folder

    ansible webservers,dbservers -m shell -a "mkdir /tmp/javafolder"

    ansible webservers -m shell -a "touch /tmp/javafolder/app.java"

    7. Add some content to app.java file.

    ansible webservers -m copy -a "content='Hello Ansible' dest=/tmp/javafolder/app.java"

    8. Read app.java file using shell module.

    ansible webservers -m shell -a "cat /tmp/javafolder/app.java"

    9. Delete app.java file.

    ansible webservers -m shell -a "rm /tmp/javafolder/app.java"

    10. Install tree command using apt module.

    ansible webservers -m apt -a "name=tree state=present"

    ReplyDelete
  8. Answer:

    1. ansible webservers -m shell -a "apt install apache2 -y"
    2. ansible webservers -m service -a "name=apache2 state=stopped"
    3. ansible webservers -m service -a "name=apache2 state=restarted"
    4. ansible webservers -m apt -a "name=apache2 state=absent purge=yes"
    5. ansible webservers -m shell -a "date"
    Answer for 6:
    6.1 ansible webservers -m shell -a "mkdir /tmp/java/"
    6.2 ansible webservers -m shell -a "touch app.java /tmp/java"
    7. ansible webservers -m copy -a "content='Hello World' dest=/tmp/java/app.java"
    8. ansible webservers -m shell -a "cat /tmp/java/app.java"
    9. ansible webservers -m shell -a "rm -ifr /tmp/java/app.java"
    10. ansible webservers -m apt -a "name=tree state=present"

    ReplyDelete
  9. 1. ansible webservers -m shell -a "apt install apache2 -y"
    2. ansible webservers -m service -a "name=apache2 state=started"
    ansible webservers -m service -a "name=apache2 state=stopped"
    3.ansible webservers -m service -a "name=apache2 state=restarted"
    4.ansible webservers -m shell -a "apt purge apache2 -y"
    5.ansible webservers -m shell -a "date"
    6. ansible webservers -m shell -a "mkdir /tmp/java"
    ansible webservers -m shell -a "touch /tmp/java/app.java"
    7. ansible webservers -m shell -a "echo "hello" >> /tmp/java/app.java"
    8. ansible webservers -m shell -a "cat /tmp/java/app.java"
    9. ansible webservers -m shell -a "rm /tmp/java/app.java"
    10.ansible webservers -m shell -a "apt install tree -y"

    ReplyDelete

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
item
DevOpsWorld: Ansible - Ad-hoc Command Assignment
Ansible - Ad-hoc Command Assignment
DevOpsWorld
https://www.devopsworld.co.in/2022/02/ansible-ad-hoc-command-assignment.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/2022/02/ansible-ad-hoc-command-assignment.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content