MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

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 Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Junior Linux Administrator: Role Blueprint, Responsibilities, Skills, KPIs, and Career Path

The **Junior Linux Administrator** supports the availability, security, and day-to-day operability of Linux-based infrastructure used by an enterprise IT organization to run internal services and business-critical applications. The role focuses on executing standard administration tasks, responding to tickets and alerts, performing routine maintenance, and following established runbooks under the guidance of senior administrators and SRE/Platform teams.

Read More

Linux Tutorials: Commands for Linux Administrator

1. sudo – Execute commands with elevated privileges, a fundamental for system administration. 2. useradd – Create a new user account, essential for managing user access. 3….

Read More

Linux Tutorials: chown command & example

The command chown, an abbreviation of change owner, is used on Unix and Unix-like operating systems to change the owner of file system files, directories. Unprivileged users…

Read More

Linux Tutorials: Commands for Linux User

ls – List directory contents. cd – Change the current directory pwd – Print the name of the current working directory. touch – Create an empty file…

Read More

Best Practices of Linux Security

User Security Password Security Securing the root account File System Security System Security User Security Avoid shared accounts Ensure each user is assigned a unique account name…

Read More

Complete Referance of Linux Security

Course Outline Introduction To Linux Security A Bit About Linux Current Security Problems which is more secure: Windows vs Linux? Requirements of a Secure OS Overview of…

Read More
Subscribe
Notify of
guest
3 Comments
Newest
Oldest Most Voted
Arturo Alvarado Esparza
Arturo Alvarado Esparza
3 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
3 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
4 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