Push Code From Ansible Server to Hosts by using Single Module (Method-2)

Share via:

Dear Readers,

In this article,we will see Push Code From Ansible Server to Hosts by using Single Module.

Modules

  • Ansible modules are discrete units of code which can be used from the command line or in a playbook task.
  • The modules also referred to as task plugins or library plugins in the Ansible.
  • Ansible ships with several modules that are called module library, which can be executed directly or remote hosts           through the playbook.
  • We can execute the modules from the command line.
  • Ansible executes each module, usually on the remote target node, and collects return values.

Steps to Follow

  1. Connect to Ansible Linux EC2 Terminal through Putty.
  2. See the full information of 2 hosts (Gathering facts).
  3. See the hostname of 2 hosts.
  4. Install package “httpd” inside 2 nodes inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  5. Upgrade package “httpd” inside 2 nodes inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  6. Remove package “httpd” inside 2 nodes inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  7. Create a file “ktexperts” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  8. Remove a file “ktexperts” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  9. Create a directory “ktexperts-dir” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  10. Remove a directory “ktexperts-dir” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”
  11. Create a user “rammy” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  12. Create a group “Ktexperts-DevOps” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  13. Add user “rammy” to group “Ktexperts-DevOps”.
  14. Remove user “rammy” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  15. Remove group “Ktexperts-DevOps” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  16. Download the package from the internet to 2 hosts.
  17. Copy file “ktexperts” from ansible server to 2 hosts.
  18. Start the service “httpd” in 2 hosts.

 

1. Connect to Ansible Linux EC2 Terminal through Putty

Switch to the root user

Switch to user “kt-ansible”

Setup Module

To gets information about the network or hardware or OS version or memory-related information the setup module will help to gather the same about the target machines.

2. See the full information of 2 hosts (Gathering facts)

Command Module

3. See the hostname of 2 hosts

The command module simply executes a specific command on the target machine and gives the output.

yum Module

4. Install package “httpd” inside 2 nodes inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

We can push code from Ansible Server to hosts by using a single module.

Here,
-a ——–> To run arbitrary.
-m ——-> To run the module.
-b ———> To become root.

Verify the package “httpd” inside the 2 Nodes “Ansible-Node-1” and “Ansible-Node-2”

5. Upgrade package “httpd” inside 2 hosts inside the 2 Nodes “Ansible-Node-1” and “Ansible-Node-2”

Verify the version of the package “httpd” inside the 2 Nodes “Ansible-Node-1” and “Ansible-Node-2”

6. Remove package “httpd” inside 2 hosts inside the 2 Nodes “Ansible-Node-1” and “Ansible-Node-2”

Verify the package “httpd” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

File Module

This module is used to create and remove files, directories.

7. Create a file “ktexperts” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Verify file “ktexperts” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

8. Remove a file “ktexperts” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Verify file “ktexperts” inside the 2 Nodes “Ansible-Node-1” and “Ansible-Node-2”

9. Create a directory “ktexperts-dir” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Verify a directory “ktexperts-dir” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

10. Remove a directory “ktexperts-dir” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Verify a directory “ktexperts-dir” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

User Module

Using this module one can create or delete users.

11. Create a user “rammy” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Verify a user “rammy” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Group Module

Using this module one can create or delete groups.

12. Create a group “Ktexperts-DevOps” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Verify a group “Ktexperts-DevOps” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

13. Add user “rammy” to group “Ktexperts-DevOps”

Verify user “rammy” inside 2 hosts Ansible-Node-1″ and “Ansible-Node-2”

14. Remove user “rammy” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Verify a user “rammy” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

15. Remove group “Ktexperts-DevOps” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Verify group “Ktexperts-DevOps” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

get_url Module

By using the get_url module, we can download packages from the internet.

16. Download the package from the internet to 2 hosts

Verify the package inside the 2 hosts

Copy Module

It is used for copying files to multiple hosts.

17. Copy file “ktexperts” from ansible server to 2 hosts

Create a file “ktexperts” in ansible server

using below command to copy a file from ansible server to hosts

Verify file “ktexperts” in 2 hosts

Service Module

By using this module, we can start and stop the services.

18. Start the service “httpd” in 2 hosts

Verify the status of service “httpd” in 2 hosts

Stop the service “httpd” in 2 hosts

Restart the service “httpd” in 2 hosts

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.

Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Add Comment