With the above default settings our inventory file now simplifies to:
``` yaml
all:
hosts:
testserver:
ansible_ssh_host:<VM-DNS-name-or-IP-address>
```
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.
Now calling ansible is simpler:
We also disable warnings about deprecated features that the 2.x version of Ansible emits.
``` shell
lcl$ ansible testserver -m ping
```
With these default values the hosts inventory file now simplifies to:
The ansible command can be used to run arbitrary commands on the remote
We can now run Ansible again and don't need to specify the inventory file any more:
ansible testserver -m ping
### Task #4: Install web application ###
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:
**Goal:** configure the managed host to run a simple Web application served by
the nginx server. This necessitates four files:
ansible testserver -m command -a uptime
1. The inventory file `~/ansible/hosts.yml` as written before.
2. A "playbook" that specifies what to configure
`~/ansible/playbooks/web.yml`.
3. The nginx's configuration file `~/ansible/playbooks/files/nginx.conf`.
4. A home page template for our Web site
`~/ansible/playbooks/templates/index.html.j2`.
You should see output similar to this:
To make our playbook more generic, we will use an ansible group called
`webservers` holding our managed server, so that we can then later easily add
more servers which Ansible will configure identically. Modify the hostfile by
adding a definition of the group webservers, this is **left to you as an
exercise**. If you do it correctly, you should get the following inventory