Push Code From Ansible Server to Hosts by using Ad-Hoc (Method-1)

Share via:

Dear Readers,

In this article,we will see Push Code From Ansible Server to Hosts by using Ad-Hoc.

What are Ad-Hoc Commands?

  • The Ad-Hoc command is the one-liner ansible command that performs one task on the target host.
  • Use ad-hoc tasks really quick & don’t want to save for later.
  • These are quick one-liner without writing a playbook.
  • It allows you to execute simple one-line task against one or group of hosts defined on the inventory file                         configuration.
  • An Ad-Hoc command will only have two parameters, the group of a host that you want to perform the task and the        Ansible module to run.
  • The Ad-Hoc command gives you more advantage for exploring ansible itself.
  • You are able to perform tasks without creating a playbook first, such as rebooting servers, managing services,               editing the line configuration, copy a file to only one host, install only one package.

Steps to Follow

  1. Create files inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  2. Create files inside the host 1 “Ansible-Node-1”.
  3. Create files inside the host 2 “Ansible-Node-2”.
  4. Install the package “httpd” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  5. Remove the package “httpd” inside 2 nodes inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”. 
  6. Install multiple packages “httpd” and “mysql” inside 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
  7. Remove multiple packages “httpd” and “mysql” inside 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.

1. Create files inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

verify all hosts and all groups of inventory

Verify all hosts inside the group “Ktexperts-Group”

Verify all files/directories inside 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Using below command to create files inside 2 hosts

Verify all files/directories in 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

2. Create files inside the host 1 “Ansible-Node-1”

Verify the files inside the host 1 “Ansible-Node-1”
To see the list of files inside the node 1

3. Create files inside the host 2 “Ansible-Node-2”

Verify the files inside the host 2 “Ansible-Node-2”
To see the list of files inside the node 1

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

To run anything with sudo, use -b in the below command.

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

5. Remove the 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”

6. Install multiple packages “httpd” and “mysql” inside 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Verify multiple packages “httpd” and “mysql” inside 2 hosts”Ansible-Node-1″ and “Ansible-Node-2”

7. Remove multiple packages “httpd” and “mysql” inside 2 hosts “Ansible-Node-1” and “Ansible-Node-2”

Verify multiple packages “httpd” and “mysql” in 2 nodes “Ansible-Node-1” and “Ansible-Node-2”

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