Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Ansible Adhoc Commands Lab & Excercise – Part 1

Program 1 – Write a Ansible Adhoc Commands to create a group called “deploy

How to verify?
$ more /etc/group | grep deploy

Program 2 – Write a Ansible Adhoc Commands to create a user called “deploy-user” which is part of group called “deploy” and with /bin/bash shell.

How to verify?
$ more /etc/passwd | grep deploy-user

Program 3 – Write a Ansible Adhoc commands install package named “httpd” in RHEL/centos.

How to verify?
$ which httpd

Program 4 – Write a Ansible Adhoc commands to start and enable the service named “httpd”

How to verify?
$ ps -eaf | grep httpd

Program 5 – Write a Ansible commands to create a file called “index.html” in /var/www/html with some dummy html contents.

How to verify?
Browse http://x.x.x.x:80

Program 6 – Write a Ansible commands to copy a file called “second.html” in /var/www/html/second.html with some dummy html contents.

How to verify?
Browse http://x.x.x.x/second.html

Program 7 – Write a Ansible commands to install a package called “git”, “wget”.

How to verify?
$ which git
$ which wget

Program 8 – Write a Ansible Adhoc commands to clone git repo. https://github.com/scmgalaxy/ansible-role-template.

How to verify?
$ ls

Program 9 – Write a Ansible commands to reboot a self machine.

Program 10 – Write a Ansible commands to touch a file called “devopsschool.txt” in /opt/ and delete after using ansible adhoc command.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Ansible Tower Install and Setup Quick Guide

To install Red Hat Ansible Tower 3.8.6 (using ansible-tower-setup-3.8.6-2.tar.gz), your environment must meet a set of hardware, software, and system prerequisites. Below are the summarized requirements specific to this Tower…

Read More

Ansible: How to use template in Ansible using Jinja2?

Here’s a comprehensive tutorial on Ansible Templates and Jinja2, suitable for engineers or anyone preparing for an advanced Ansible role. 1. What are Ansible Templates? Ansible templates…

Read More

What is Ansible and use cases of Ansible?

What is Ansible? Ansible is an open-source automation tool used for configuration management, application deployment, and task automation. It simplifies complex IT tasks by automating them using…

Read More

Ansible Tutorials: Calling one Play & Tasks from another play in Playbook

import_tasks module The Ansible import_tasks module is used to import a list of tasks from a file into the current playbook for subsequent execution. The name of…

Read More

Ansible Tutorial: Anatomy of Ansible playbook defined!

host defines the target machines: one or more groups or host patterns, separated by colons that should match hosts in the inventory. all is a group that…

Read More

Complete Ansible Certification Guide & tutorials

What is Ansible? Ansible is an open-source tool which can automate the configuration of all the systems. With ansible a small team of system administrator can write…

Read More
Subscribe
Notify of
guest
3 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Arturo Alvarado Esparza
Arturo Alvarado Esparza
2 years ago

root@ip-172-31-24-147:~# ansible all -i inventory -m group -a “state=present name=deploy” -u ubuntu –key-file=node.pem -b
34.226.195.116 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “changed”: false,
  “gid”: 1001,
  “name”: “deploy”,
  “state”: “present”,
  “system”: false
}
54.174.239.89 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “changed”: false,
  “gid”: 1001,
  “name”: “deploy”,
  “state”: “present”,
  “system”: false
}
54.85.203.183 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “changed”: false,
  “gid”: 1001,
  “name”: “deploy”,
  “state”: “present”,
  “system”: false
}
root@ip-172-31-24-147:~# more /etc/group | grep deploy
deploy:x:1001:
deploydfhh:x:1002:

2
root@ip-172-31-24-147:~# ansible all -i inventory -m user -a “name=deploy-user groups=deploy state=present shell=/bin/bash” -u ubuntu –key-file=node.pem -b 54.174.239.89 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “append”: false,
  “changed”: false,
  “comment”: “”,
  “group”: 1001,
  “groups”: “deploy”,
  “home”: “/home/deploy-user”,
  “move_home”: false,
  “name”: “deploy-user”,
  “shell”: “/bin/bash”,
  “state”: “present”,
  “uid”: 1001
}
34.226.195.116 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “append”: false,
  “changed”: false,
  “comment”: “”,
  “group”: 1001,
  “groups”: “deploy”,
  “home”: “/home/deploy-user”,
  “move_home”: false,
  “name”: “deploy-user”,
  “shell”: “/bin/bash”,
  “state”: “present”,
  “uid”: 1001
}
54.85.203.183 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “append”: false,
  “changed”: false,
  “comment”: “”,
  “group”: 1001,
  “groups”: “deploy”,
  “home”: “/home/deploy-user”,
  “move_home”: false,
  “name”: “deploy-user”,
  “shell”: “/bin/bash”,
  “state”: “present”,
  “uid”: 1001
}
root@ip-172-31-24-147:~# more /etc/passwd | grep deploy-user
deploy-user:x:1001:1001::/home/deploy-user:/bin/bash

3
root@ip-172-31-24-147:~# ansible web -i inventory -m apt -a”state=latest name=httpd” -u ubuntu –key-file=node.pem -b
54.174.239.89 | FAILED! => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “cache_update_time”: 1695090101,
  “cache_updated”: false,
  “changed”: false,
  “msg”: “‘/usr/bin/apt-get -y -o \”Dpkg::Options::=–force-confdef\” -o \”Dpkg::Options::=–force-confold\”    install ‘httpd” failed: E: Package ‘httpd’ has no installation candidate\n”,
  “rc”: 100,
  “stderr”: “E: Package ‘httpd’ has no installation candidate\n”,
  “stderr_lines”: [
    “E: Package ‘httpd’ has no installation candidate”
  ],
  “stdout”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\nPackage httpd is a virtual package provided by:\n nginx-core 1.18.0-6ubuntu14.4\n apache2 2.4.52-1ubuntu4.6\n\n”,
  “stdout_lines”: [
    “Reading package lists…”,
    “Building dependency tree…”,
    “Reading state information…”,
    “Package httpd is a virtual package provided by:”,
    ” nginx-core 1.18.0-6ubuntu14.4″,
    ” apache2 2.4.52-1ubuntu4.6″,
    “”
  ]
}
54.85.203.183 | FAILED! => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “cache_update_time”: 1698931978,
  “cache_updated”: false,
  “changed”: false,
  “msg”: “‘/usr/bin/apt-get -y -o \”Dpkg::Options::=–force-confdef\” -o \”Dpkg::Options::=–force-confold\”    install ‘httpd” failed: E: Package ‘httpd’ has no installation candidate\n”,
  “rc”: 100,
  “stderr”: “E: Package ‘httpd’ has no installation candidate\n”,
  “stderr_lines”: [
    “E: Package ‘httpd’ has no installation candidate”
  ],
  “stdout”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\nPackage httpd is a virtual package provided by:\n nginx-light 1.18.0-6ubuntu14.4\n nginx-full 1.18.0-6ubuntu14.4\n nginx-extras 1.18.0-6ubuntu14.4\n lighttpd 1.4.63-1ubuntu3.1\n nginx-core 1.18.0-6ubuntu14.4\n apache2 2.4.52-1ubuntu4.6\n yaws 2.1.1+dfsg-1\n webfs 1.21+ds1-12\n tntnet 2.2.1-4build2\n mini-httpd 1.30-2build1\n micro-httpd 20140814-2.1\n\n”,
  “stdout_lines”: [
    “Reading package lists…”,
    “Building dependency tree…”,
    “Reading state information…”,
    “Package httpd is a virtual package provided by:”,
    ” nginx-light 1.18.0-6ubuntu14.4″,
    ” nginx-full 1.18.0-6ubuntu14.4″,
    ” nginx-extras 1.18.0-6ubuntu14.4″,
    ” lighttpd 1.4.63-1ubuntu3.1″,
    ” nginx-core 1.18.0-6ubuntu14.4″,
    ” apache2 2.4.52-1ubuntu4.6″,
    ” yaws 2.1.1+dfsg-1″,
    ” webfs 1.21+ds1-12″,
    ” tntnet 2.2.1-4build2″,
    ” mini-httpd 1.30-2build1″,
    ” micro-httpd 20140814-2.1″,
    “”
  ]
}
root@ip-172-31-24-147:~# ansible web -i inventory -m apt -a”state=latest name=apache2″ -u ubuntu –key-file=node.pem -b
54.174.239.89 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “cache_update_time”: 1695090101,
  “cache_updated”: false,
  “changed”: false
}
54.85.203.183 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “cache_update_time”: 1698931978,
  “cache_updated”: false,
  “changed”: false
}
root@ip-172-31-24-147:~# which apache2
/usr/sbin/apache2

4
ansible all -i inventory -m service -a”name=apache2 state=started” -u ubuntu –key-file=node.pem -b
root@ip-172-31-24-147:~# ps -fea| grep http
root    17682  7732 35 16:06 pts/33  00:00:00 /usr/bin/python3 /usr/bin/ansible all -i 54.85.203.183,54.174.239.89,34.226.195.116 -m apt -a name=httpd>=2.4 state=latest -u ubuntu –key=node.pem -b
root    17686  17682 1 16:06 pts/33  00:00:00 /usr/bin/python3 /usr/bin/ansible all -i 54.85.203.183,54.174.239.89,34.226.195.116 -m apt -a name=httpd>=2.4 state=latest -u ubuntu –key=node.pem -b
root    17748  17737 0 16:06 pts/27  00:00:00 /usr/bin/apt-mark manual httpd
root    17752  5990 0 16:06 pts/24  00:00:00 grep –color=auto http

5
ansible all -i inventory -m copy -a”src=index.html dest=/var/www/html/index.html” -u ubuntu –key-file=node.pem -b

root@ip-172-31-24-147:~# ansible web -i inventory -m apt -a”state=latest name=git” -u ubuntu –key-file=node.pem -b
54.174.239.89 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “cache_update_time”: 1695090101,
  “cache_updated”: false,
  “changed”: false
}
54.85.203.183 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “cache_update_time”: 1698931978,
  “cache_updated”: false,
  “changed”: false
}
root@ip-172-31-24-147:~# ansible web -i inventory -m apt -a”state=latest name=wget” -u ubuntu –key-file=node.pem -b
54.174.239.89 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “cache_update_time”: 1695090101,
  “cache_updated”: false,
  “changed”: false
}
54.85.203.183 | SUCCESS => {
  “ansible_facts”: {
    “discovered_interpreter_python”: “/usr/bin/python3”
  },
  “cache_update_time”: 1698931978,
  “cache_updated”: false,
  “changed”: false
}
root@ip-172-31-24-147:~# which git
/usr/bin/git
root@ip-172-31-24-147:~# which wget
/usr/bin/wget
root@ip-172-31-24-147:~#

Jacek Szałęga
Jacek Szałęga
2 years ago

Tested on Ubuntu OS.
ansible all -i inventory -m group -a”name=deploy state=present” -u ubuntu –key-file=node.pem -b
ansible all -i inventory -m user -a”name=deploy-user group=deploy shell=/bin/bash” -u ubuntu –key-file=node.pem -b
ansible web -i inventory -m apt -a”state=latest name=apache2″ -u ubuntu –key-file=node.pem -b
ansible web -i inventory -m service -a”name=apache2 state=started” -u ubuntu –key-file=node.pem -b
ansible web -i inventory -m copy -a”src=index.html dest=/var/www/html/” -u ubuntu –key-file=node.pem -b
ansible web -i inventory -m copy -a”content=’second file content’ dest=/var/www/html/second.html” -u ubuntu –key-file=node.pem -b
ansible web -i inventory -m apt -a”state=present name=git,wget” -u ubuntu –key-file=node.pem -b
ansible web -i inventory -m git -a”repo=https://github.com/scmgalaxy/ansible-role-template dest=/root/ansible-role-template clone=yes update=yes” -u ubuntu –key-file=node.pem -b
ansible web -i inventory -m reboot -u ubuntu –key-file=node.pem -b
ansible web -i inventory -m file -a”path=/opt/devopsschool.txt state=touch” -u ubuntu –key-file=node.pem -b
ansible web -i inventory -m file -a”path=/opt/devopsschool.txt state=absent” -u ubuntu –key-file=node.pem -b

trackback
Ansible Assginment - May/2022 - Adhoc Commands - Playbook - Inventory - DevOps - DevSecOps - SRE - DataOps - AIOps
3 years ago

[…] Ansible Adhoc Commands Lab & Excercise – Part 1 Ansible Inventory Lab & Excercise – Part 1 Ansible Playbook Lab & Excercise – Part 2 Search for: […]

3
0
Would love your thoughts, please comment.x
()
x