We can manage files using Ansible ad-hoc commands, for example, creating new files, removing existing files and modifying it etc. It means ‘nginx’ package has been uninstalled successfully.ģ. In the above example, we can see changed is equal to true. $ansibletest_group -b -m yum -a "name=nginx state=absent" We use ‘state=absent’ in the ad-hoc command to uninstall any package as below. The ‘-b’ option is used to run the command as root as it requires sudo privilege. In the above example, we have installed ‘nginx’ package to the client node. $ansibletest_group -b -m yum -a "name=nginx state=latest" We can manage packages like installing and uninstalling a package or checking the status of the package on the nodes.
In the above example, we have filtered out hostname of the server using ‘ansible_nodename’.Ģ. $ansible webservers -m setup -a "filter=ansible_nodename" We get a lot of data as an output, however, if we are interested in specific fact, we can use ‘filter’ option as below.
In the above example, we used ‘setup’ module to get the details about the nodes in the webservers group. If we want to collect information of a specific host or group of host. Given below are some ansible ad-hoc commands that are used in day to day management of our infrastructure:ġ. In the above command, we used ‘ping’ module to test connection between master server and client named ‘ansible_’.
Ansible run remote command installpkg software#
Web development, programming languages, Software testing & others Start Your Free Software Development Course