Using Ansible to configure remote CentOS server.
Ansible is not very convenient to perform initial server configuration, specifically I have found it hard to perform the following tasks:
- Transfer an SHH public key to the remote server right after server initialization.
- Programmatically add server SSH fingerprint to local "known_hosts" file
- Programmatically change SSH port.
Fabric can easily automate these tasks.
Fabric is a high level imperative style shell command execution library written in python.
I found it very useful to perform initial configuration of a remote server, having only root username and password provided by the cloud operator when you buy a VM instance.
All you need to do is:
pip install fabric
And then Fabric scripts can be run as a regular python scripts.
Since Fabric is imperative it is somewhat cumbersome to achieve idempotency, and a lot of if
statements have to be used to check for various conditions. In this regard, Ansible abstracts away a lot of such complexities.
So as soon as initial server configuration is completed, you can switch to Ansible to perform the rest of configuration tasks.