Suppose I have a host that is, among other things, a web server, where the related Ansible role installs nginx
, performs some essential configuration in /etc/nginx
, and opens up ports 80 and 443 in the firewall.
At some point I want that particular host to not be a web server any more, because for some reason I moved that service elsewhere. Just removing the server from [webservers]
in the inventory would leave garbage in the server. Ideally, I'd like to uninstall nginx
, remove the /etc/nginx
directory (and some other directories), and close up ports 80 and 443 in the firewall.
In Puppet I can do this. A host that is a web server will have something like this in its configuration:
class { 'nginx':
ensure => present,
}
and all I have to do is to replace "present" with "absent". If the nginx
class is well-written, it will undo the changes it has made. (Typically an administrator will replace "present" with "absent", and later, when he's certain that all affected hosts have undone the configuration, he will remove the item from the manifest.)
What's more, I think that the Puppet firewall module automatically removes firewall rules that can't be found in the manifest any more; so I think that, for the firewall, you don't even need to do that "absent" thing above, the firewall will automatically close up anyway.
How can I achieve these things with Ansible?
ensure => present
toensure => absent
which will also... How to do the same with ansible" etc. Ideally with an example of anything you have already tried.