filmov
tv
RHCE 8 - Ansible - Running Ad-Hoc Commands
![preview_player](https://i.ytimg.com/vi/Fus301ZPvNE/maxresdefault.jpg)
Показать описание
If you want to quickly see what Ansible can do in Automating your environment then we can use ad-hoc commands from the Ansible controller. We have an inventory of just 2 hosts for our test environment and we can run a simple check using ansible all -i inventory -m ping . This will run the ping module on the controller that test for a response from Python on the managed hosts. It is not an ICMP ping that you may at first think. There are different modules to support different devices. the win_ping module for Windows devices and the ios_ping for Cisco devices and so on. We can use ansible-doc -l to list all the available modules. Of course, there are many modules and we move on to see the idempotency of Ansible by using the user module:
ansible all -i inventory -m user "name=tux state=present"
If the user tux is on the system nothing needs to be done. We can prove this by creating a new user:
ansible all -i inventory -m user "mary=tux state=present"
And we see the state is changed on the host indicating the user has been created. Changing the state to be removed will remove the user account form the target systems.
ansible all -i inventory -m user "name=tux state=present"
If the user tux is on the system nothing needs to be done. We can prove this by creating a new user:
ansible all -i inventory -m user "mary=tux state=present"
And we see the state is changed on the host indicating the user has been created. Changing the state to be removed will remove the user account form the target systems.