We can now simplify the configuration of Ansible by using an ansible.cfg file which allows us to set some defaults.
In the playbooks directory create the file ansible.cfg:
[defaults]
inventory = hosts
remote_user = ubuntu
private_key_file = <pathtokeyfile.pem>
host_key_checking = false
deprecation_warnings = false
Among the default options we also disable SSH's host key checking. This is convenient when we distroy and recreate the managed server (it will get a new host key every time). In production this may be a security risk.
We also disable warnings about deprecated features that the 2.x version of Ansible emits.
With these default values the hosts inventory file now simplifies to:
We can now run Ansible again and don't need to specify the inventory file any more:
ansible testserver -m ping
The ansible command can be used to run arbitrary commands on the remote machines. Use the -m command option and add the command in the -a option. For example to execute the uptime command: