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
- Create files inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
- Create files inside the host 1 “Ansible-Node-1”.
- Create files inside the host 2 “Ansible-Node-2”.
- Install the package “httpd” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
- Remove the package “httpd” inside 2 nodes inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
- Install multiple packages “httpd” and “mysql” inside 2 hosts “Ansible-Node-1” and “Ansible-Node-2”.
- 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
1 2 3 4 5 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible all --list-hosts hosts (2): 172.31.11.251 172.31.2.38 |
Verify all hosts inside the group “Ktexperts-Group”
1 2 3 4 5 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group --list-hosts hosts (2): 172.31.11.251 172.31.2.38 |
Verify all files/directories inside 2 hosts “Ansible-Node-1” and “Ansible-Node-2”
1 2 3 4 5 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -a "ls" 172.31.11.251 | CHANGED | rc=0 >> 172.31.2.38 | CHANGED | rc=0 >> |
Using below command to create files inside 2 hosts
1 2 3 4 5 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -a "touch kt-1 kt-2 kt-3" 172.31.11.251 | CHANGED | rc=0 >> 172.31.2.38 | CHANGED | rc=0 >> |
Verify all files/directories in 2 hosts “Ansible-Node-1” and “Ansible-Node-2”
1 2 3 4 5 6 7 8 9 10 11 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -a "ls" 172.31.2.38 | CHANGED | rc=0 >> kt-1 kt-2 kt-3 172.31.11.251 | CHANGED | rc=0 >> kt-1 kt-2 kt-3 |
2. Create files inside the host 1 “Ansible-Node-1”
1 2 3 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group[0] -a "touch kt-4" 172.31.11.251 | CHANGED | rc=0 >> |
Verify the files inside the host 1 “Ansible-Node-1”
To see the list of files inside the node 1
1 2 3 4 5 6 |
kt-ansible@ip-172-31-6-252 ~]$ ansible Ktexperts-Nodes-Group[0] -a "ls" 172.31.5.201 | CHANGED | rc=0 >> kt1 kt2 kt3 |
3. Create files inside the host 2 “Ansible-Node-2”
1 2 3 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group[1] -a "touch kt-4" 172.31.11.251 | CHANGED | rc=0 >> |
Verify the files inside the host 2 “Ansible-Node-2”
To see the list of files inside the node 1
1 2 3 4 5 6 |
kt-ansible@ip-172-31-6-252 ~]$ ansible Ktexperts-Nodes-Group[1] -a "ls" 172.31.5.201 | CHANGED | rc=0 >> kt1 kt2 kt3 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -b -a "yum install httpd -y" 172.31.11.251 | CHANGED | rc=0 >> Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.41-1.amzn2.0.1 will be installed --> Processing Dependency: httpd-tools = 2.4.41-1.amzn2.0.1 for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: httpd-filesystem = 2.4.41-1.amzn2.0.1 for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: system-logos-httpd for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: mod_http2 for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: httpd-filesystem for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: /etc/mime.types for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Running transaction check ---> Package apr.x86_64 0:1.6.3-5.amzn2.0.2 will be installed ---> Package apr-util.x86_64 0:1.6.1-5.amzn2.0.2 will be installed --> Processing Dependency: apr-util-bdb(x86-64) = 1.6.1-5.amzn2.0.2 for package: apr-util-1.6.1-5.amzn2.0.2.x86_64 ---> Package generic-logos-httpd.noarch 0:18.0.0-4.amzn2 will be installed ---> Package httpd-filesystem.noarch 0:2.4.41-1.amzn2.0.1 will be installed ---> Package httpd-tools.x86_64 0:2.4.41-1.amzn2.0.1 will be installed ---> Package mailcap.noarch 0:2.1.41-2.amzn2 will be installed ---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be installed --> Running transaction check ---> Package apr-util-bdb.x86_64 0:1.6.1-5.amzn2.0.2 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: httpd x86_64 2.4.41-1.amzn2.0.1 amzn2-core 1.3 M Installing for dependencies: apr x86_64 1.6.3-5.amzn2.0.2 amzn2-core 118 k apr-util x86_64 1.6.1-5.amzn2.0.2 amzn2-core 99 k apr-util-bdb x86_64 1.6.1-5.amzn2.0.2 amzn2-core 19 k generic-logos-httpd noarch 18.0.0-4.amzn2 amzn2-core 19 k httpd-filesystem noarch 2.4.41-1.amzn2.0.1 amzn2-core 23 k httpd-tools x86_64 2.4.41-1.amzn2.0.1 amzn2-core 87 k mailcap noarch 2.1.41-2.amzn2 amzn2-core 31 k mod_http2 x86_64 1.15.3-2.amzn2 amzn2-core 146 k Transaction Summary ================================================================================ Install 1 Package (+8 Dependent packages) Total download size: 1.8 M Installed size: 5.1 M Downloading packages: -------------------------------------------------------------------------------- Total 10 MB/s | 1.8 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : apr-1.6.3-5.amzn2.0.2.x86_64 1/9 Installing : apr-util-bdb-1.6.1-5.amzn2.0.2.x86_64 2/9 Installing : apr-util-1.6.1-5.amzn2.0.2.x86_64 3/9 Installing : httpd-tools-2.4.41-1.amzn2.0.1.x86_64 4/9 Installing : generic-logos-httpd-18.0.0-4.amzn2.noarch 5/9 Installing : mailcap-2.1.41-2.amzn2.noarch 6/9 Installing : httpd-filesystem-2.4.41-1.amzn2.0.1.noarch 7/9 Installing : mod_http2-1.15.3-2.amzn2.x86_64 8/9 Installing : httpd-2.4.41-1.amzn2.0.1.x86_64 9/9 Verifying : apr-util-1.6.1-5.amzn2.0.2.x86_64 1/9 Verifying : apr-util-bdb-1.6.1-5.amzn2.0.2.x86_64 2/9 Verifying : httpd-2.4.41-1.amzn2.0.1.x86_64 3/9 Verifying : httpd-filesystem-2.4.41-1.amzn2.0.1.noarch 4/9 Verifying : mod_http2-1.15.3-2.amzn2.x86_64 5/9 Verifying : apr-1.6.3-5.amzn2.0.2.x86_64 6/9 Verifying : mailcap-2.1.41-2.amzn2.noarch 7/9 Verifying : generic-logos-httpd-18.0.0-4.amzn2.noarch 8/9 Verifying : httpd-tools-2.4.41-1.amzn2.0.1.x86_64 9/9 Installed: httpd.x86_64 0:2.4.41-1.amzn2.0.1 Dependency Installed: apr.x86_64 0:1.6.3-5.amzn2.0.2 apr-util.x86_64 0:1.6.1-5.amzn2.0.2 apr-util-bdb.x86_64 0:1.6.1-5.amzn2.0.2 generic-logos-httpd.noarch 0:18.0.0-4.amzn2 httpd-filesystem.noarch 0:2.4.41-1.amzn2.0.1 httpd-tools.x86_64 0:2.4.41-1.amzn2.0.1 mailcap.noarch 0:2.1.41-2.amzn2 mod_http2.x86_64 0:1.15.3-2.amzn2 Complete! 172.31.2.38 | CHANGED | rc=0 >> Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.41-1.amzn2.0.1 will be installed --> Processing Dependency: httpd-tools = 2.4.41-1.amzn2.0.1 for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: httpd-filesystem = 2.4.41-1.amzn2.0.1 for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: system-logos-httpd for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: mod_http2 for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: httpd-filesystem for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: /etc/mime.types for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.41-1.amzn2.0.1.x86_64 --> Running transaction check ---> Package apr.x86_64 0:1.6.3-5.amzn2.0.2 will be installed ---> Package apr-util.x86_64 0:1.6.1-5.amzn2.0.2 will be installed --> Processing Dependency: apr-util-bdb(x86-64) = 1.6.1-5.amzn2.0.2 for package: apr-util-1.6.1-5.amzn2.0.2.x86_64 ---> Package generic-logos-httpd.noarch 0:18.0.0-4.amzn2 will be installed ---> Package httpd-filesystem.noarch 0:2.4.41-1.amzn2.0.1 will be installed ---> Package httpd-tools.x86_64 0:2.4.41-1.amzn2.0.1 will be installed ---> Package mailcap.noarch 0:2.1.41-2.amzn2 will be installed ---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be installed --> Running transaction check ---> Package apr-util-bdb.x86_64 0:1.6.1-5.amzn2.0.2 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: httpd x86_64 2.4.41-1.amzn2.0.1 amzn2-core 1.3 M Installing for dependencies: apr x86_64 1.6.3-5.amzn2.0.2 amzn2-core 118 k apr-util x86_64 1.6.1-5.amzn2.0.2 amzn2-core 99 k apr-util-bdb x86_64 1.6.1-5.amzn2.0.2 amzn2-core 19 k generic-logos-httpd noarch 18.0.0-4.amzn2 amzn2-core 19 k httpd-filesystem noarch 2.4.41-1.amzn2.0.1 amzn2-core 23 k httpd-tools x86_64 2.4.41-1.amzn2.0.1 amzn2-core 87 k mailcap noarch 2.1.41-2.amzn2 amzn2-core 31 k mod_http2 x86_64 1.15.3-2.amzn2 amzn2-core 146 k Transaction Summary ================================================================================ Install 1 Package (+8 Dependent packages) Total download size: 1.8 M Installed size: 5.1 M Downloading packages: -------------------------------------------------------------------------------- Total 11 MB/s | 1.8 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : apr-1.6.3-5.amzn2.0.2.x86_64 1/9 Installing : apr-util-bdb-1.6.1-5.amzn2.0.2.x86_64 2/9 Installing : apr-util-1.6.1-5.amzn2.0.2.x86_64 3/9 Installing : httpd-tools-2.4.41-1.amzn2.0.1.x86_64 4/9 Installing : generic-logos-httpd-18.0.0-4.amzn2.noarch 5/9 Installing : mailcap-2.1.41-2.amzn2.noarch 6/9 Installing : httpd-filesystem-2.4.41-1.amzn2.0.1.noarch 7/9 Installing : mod_http2-1.15.3-2.amzn2.x86_64 8/9 Installing : httpd-2.4.41-1.amzn2.0.1.x86_64 9/9 Verifying : apr-util-1.6.1-5.amzn2.0.2.x86_64 1/9 Verifying : apr-util-bdb-1.6.1-5.amzn2.0.2.x86_64 2/9 Verifying : httpd-2.4.41-1.amzn2.0.1.x86_64 3/9 Verifying : httpd-filesystem-2.4.41-1.amzn2.0.1.noarch 4/9 Verifying : mod_http2-1.15.3-2.amzn2.x86_64 5/9 Verifying : apr-1.6.3-5.amzn2.0.2.x86_64 6/9 Verifying : mailcap-2.1.41-2.amzn2.noarch 7/9 Verifying : generic-logos-httpd-18.0.0-4.amzn2.noarch 8/9 Verifying : httpd-tools-2.4.41-1.amzn2.0.1.x86_64 9/9 Installed: httpd.x86_64 0:2.4.41-1.amzn2.0.1 Dependency Installed: apr.x86_64 0:1.6.3-5.amzn2.0.2 apr-util.x86_64 0:1.6.1-5.amzn2.0.2 apr-util-bdb.x86_64 0:1.6.1-5.amzn2.0.2 generic-logos-httpd.noarch 0:18.0.0-4.amzn2 httpd-filesystem.noarch 0:2.4.41-1.amzn2.0.1 httpd-tools.x86_64 0:2.4.41-1.amzn2.0.1 mailcap.noarch 0:2.1.41-2.amzn2 mod_http2.x86_64 0:1.15.3-2.amzn2 Complete! |
Verify the package “httpd” inside the 2 Nodes “Ansible-Node-1” and “Ansible-Node-2”
1 2 3 4 5 6 7 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -b -a "which httpd" 172.31.11.251 | CHANGED | rc=0 >> /sbin/httpd 172.31.2.38 | CHANGED | rc=0 >> /sbin/httpd |
5. Remove the package “httpd” inside 2 hosts inside the 2 Nodes “Ansible-Node-1” and “Ansible-Node-2”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -b -a "yum remove httpd -y" 172.31.11.251 | CHANGED | rc=0 >> Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.41-1.amzn2.0.1 will be erased --> Processing Dependency: httpd-mmn = 20120211x8664 for package: mod_http2-1.15.3-2.amzn2.x86_64 --> Running transaction check ---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: httpd x86_64 2.4.41-1.amzn2.0.1 @amzn2-core 4.0 M Removing for dependencies: mod_http2 x86_64 1.15.3-2.amzn2 @amzn2-core 378 k Transaction Summary ================================================================================ Remove 1 Package (+1 Dependent package) Installed size: 4.3 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : httpd-2.4.41-1.amzn2.0.1.x86_64 1/2 Erasing : mod_http2-1.15.3-2.amzn2.x86_64 2/2 Verifying : mod_http2-1.15.3-2.amzn2.x86_64 1/2 Verifying : httpd-2.4.41-1.amzn2.0.1.x86_64 2/2 Removed: httpd.x86_64 0:2.4.41-1.amzn2.0.1 Dependency Removed: mod_http2.x86_64 0:1.15.3-2.amzn2 Complete! 172.31.2.38 | CHANGED | rc=0 >> Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.41-1.amzn2.0.1 will be erased --> Processing Dependency: httpd-mmn = 20120211x8664 for package: mod_http2-1.15.3-2.amzn2.x86_64 --> Running transaction check ---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: httpd x86_64 2.4.41-1.amzn2.0.1 @amzn2-core 4.0 M Removing for dependencies: mod_http2 x86_64 1.15.3-2.amzn2 @amzn2-core 378 k Transaction Summary ================================================================================ Remove 1 Package (+1 Dependent package) Installed size: 4.3 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : httpd-2.4.41-1.amzn2.0.1.x86_64 1/2 Erasing : mod_http2-1.15.3-2.amzn2.x86_64 2/2 Verifying : mod_http2-1.15.3-2.amzn2.x86_64 1/2 Verifying : httpd-2.4.41-1.amzn2.0.1.x86_64 2/2 Removed: httpd.x86_64 0:2.4.41-1.amzn2.0.1 Dependency Removed: mod_http2.x86_64 0:1.15.3-2.amzn2 Complete! |
Verify the package “httpd” inside the 2 hosts “Ansible-Node-1” and “Ansible-Node-2”
1 2 3 4 5 6 7 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -b -a "which httpd" 172.31.2.38 | FAILED | rc=1 >> which: no httpd in (/sbin:/bin:/usr/sbin:/usr/bin)non-zero return code 172.31.11.251 | FAILED | rc=1 >> which: no httpd in (/sbin:/bin:/usr/sbin:/usr/bin)non-zero return code |
6. Install multiple packages “httpd” and “mysql” inside 2 hosts “Ansible-Node-1” and “Ansible-Node-2”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -b -a "yum install httpd mysql -y" 172.31.2.38 | CHANGED | rc=0 >> Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.41-1.amzn2.0.1 will be installed --> Processing Dependency: mod_http2 for package: httpd-2.4.41-1.amzn2.0.1.x86_64 ---> Package mariadb.x86_64 1:5.5.64-1.amzn2 will be installed --> Running transaction check ---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: httpd x86_64 2.4.41-1.amzn2.0.1 amzn2-core 1.3 M mariadb x86_64 1:5.5.64-1.amzn2 amzn2-core 9.0 M Installing for dependencies: mod_http2 x86_64 1.15.3-2.amzn2 amzn2-core 146 k Transaction Summary ================================================================================ Install 2 Packages (+1 Dependent package) Total download size: 10 M Installed size: 53 M Downloading packages: -------------------------------------------------------------------------------- Total 35 MB/s | 10 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : httpd-2.4.41-1.amzn2.0.1.x86_64 1/3 Installing : mod_http2-1.15.3-2.amzn2.x86_64 2/3 Installing : 1:mariadb-5.5.64-1.amzn2.x86_64 3/3 Verifying : mod_http2-1.15.3-2.amzn2.x86_64 1/3 Verifying : 1:mariadb-5.5.64-1.amzn2.x86_64 2/3 Verifying : httpd-2.4.41-1.amzn2.0.1.x86_64 3/3 Installed: httpd.x86_64 0:2.4.41-1.amzn2.0.1 mariadb.x86_64 1:5.5.64-1.amzn2 Dependency Installed: mod_http2.x86_64 0:1.15.3-2.amzn2 Complete! 172.31.11.251 | CHANGED | rc=0 >> Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.41-1.amzn2.0.1 will be installed --> Processing Dependency: mod_http2 for package: httpd-2.4.41-1.amzn2.0.1.x86_64 ---> Package mariadb.x86_64 1:5.5.64-1.amzn2 will be installed --> Running transaction check ---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: httpd x86_64 2.4.41-1.amzn2.0.1 amzn2-core 1.3 M mariadb x86_64 1:5.5.64-1.amzn2 amzn2-core 9.0 M Installing for dependencies: mod_http2 x86_64 1.15.3-2.amzn2 amzn2-core 146 k Transaction Summary ================================================================================ Install 2 Packages (+1 Dependent package) Total download size: 10 M Installed size: 53 M Downloading packages: -------------------------------------------------------------------------------- Total 33 MB/s | 10 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : httpd-2.4.41-1.amzn2.0.1.x86_64 1/3 Installing : mod_http2-1.15.3-2.amzn2.x86_64 2/3 Installing : 1:mariadb-5.5.64-1.amzn2.x86_64 3/3 Verifying : mod_http2-1.15.3-2.amzn2.x86_64 1/3 Verifying : 1:mariadb-5.5.64-1.amzn2.x86_64 2/3 Verifying : httpd-2.4.41-1.amzn2.0.1.x86_64 3/3 Installed: httpd.x86_64 0:2.4.41-1.amzn2.0.1 mariadb.x86_64 1:5.5.64-1.amzn2 Dependency Installed: mod_http2.x86_64 0:1.15.3-2.amzn2 Complete! |
Verify multiple packages “httpd” and “mysql” inside 2 hosts”Ansible-Node-1″ and “Ansible-Node-2”
1 2 3 4 5 6 7 8 9 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -b -a "which mysql httpd" 172.31.11.251 | CHANGED | rc=0 >> /bin/mysql /sbin/httpd 172.31.2.38 | CHANGED | rc=0 >> /bin/mysql /sbin/httpd |
7. Remove multiple packages “httpd” and “mysql” inside 2 hosts “Ansible-Node-1” and “Ansible-Node-2”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -b -a "yum remove httpd mysql -y" 172.31.11.251 | CHANGED | rc=0 >> Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.41-1.amzn2.0.1 will be erased --> Processing Dependency: httpd-mmn = 20120211x8664 for package: mod_http2-1.15.3-2.amzn2.x86_64 ---> Package mariadb.x86_64 1:5.5.64-1.amzn2 will be erased --> Running transaction check ---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: httpd x86_64 2.4.41-1.amzn2.0.1 @amzn2-core 4.0 M mariadb x86_64 1:5.5.64-1.amzn2 @amzn2-core 49 M Removing for dependencies: mod_http2 x86_64 1.15.3-2.amzn2 @amzn2-core 378 k Transaction Summary ================================================================================ Remove 2 Packages (+1 Dependent package) Installed size: 53 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : httpd-2.4.41-1.amzn2.0.1.x86_64 1/3 Erasing : mod_http2-1.15.3-2.amzn2.x86_64 2/3 Erasing : 1:mariadb-5.5.64-1.amzn2.x86_64 3/3 Verifying : mod_http2-1.15.3-2.amzn2.x86_64 1/3 Verifying : 1:mariadb-5.5.64-1.amzn2.x86_64 2/3 Verifying : httpd-2.4.41-1.amzn2.0.1.x86_64 3/3 Removed: httpd.x86_64 0:2.4.41-1.amzn2.0.1 mariadb.x86_64 1:5.5.64-1.amzn2 Dependency Removed: mod_http2.x86_64 0:1.15.3-2.amzn2 Complete! 172.31.2.38 | CHANGED | rc=0 >> Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.41-1.amzn2.0.1 will be erased --> Processing Dependency: httpd-mmn = 20120211x8664 for package: mod_http2-1.15.3-2.amzn2.x86_64 ---> Package mariadb.x86_64 1:5.5.64-1.amzn2 will be erased --> Running transaction check ---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: httpd x86_64 2.4.41-1.amzn2.0.1 @amzn2-core 4.0 M mariadb x86_64 1:5.5.64-1.amzn2 @amzn2-core 49 M Removing for dependencies: mod_http2 x86_64 1.15.3-2.amzn2 @amzn2-core 378 k Transaction Summary ================================================================================ Remove 2 Packages (+1 Dependent package) Installed size: 53 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : httpd-2.4.41-1.amzn2.0.1.x86_64 1/3 Erasing : mod_http2-1.15.3-2.amzn2.x86_64 2/3 Erasing : 1:mariadb-5.5.64-1.amzn2.x86_64 3/3 Verifying : mod_http2-1.15.3-2.amzn2.x86_64 1/3 Verifying : 1:mariadb-5.5.64-1.amzn2.x86_64 2/3 Verifying : httpd-2.4.41-1.amzn2.0.1.x86_64 3/3 Removed: httpd.x86_64 0:2.4.41-1.amzn2.0.1 mariadb.x86_64 1:5.5.64-1.amzn2 Dependency Removed: mod_http2.x86_64 0:1.15.3-2.amzn2 Complete! |
Verify multiple packages “httpd” and “mysql” in 2 nodes “Ansible-Node-1” and “Ansible-Node-2”
1 2 3 4 5 6 7 8 9 |
[kt-ansible@ip-172-31-15-116 ~]$ ansible Ktexperts-Group -b -a "which mysql httpd" 172.31.2.38 | FAILED | rc=2 >> which: no mysql in (/sbin:/bin:/usr/sbin:/usr/bin) which: no httpd in (/sbin:/bin:/usr/sbin:/usr/bin)non-zero return code 172.31.11.251 | FAILED | rc=2 >> which: no mysql in (/sbin:/bin:/usr/sbin:/usr/bin) which: no httpd in (/sbin:/bin:/usr/sbin:/usr/bin)non-zero return code |
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