ansible - setting up inventory.ini
To setup ansible to manage your server, we can use inventory.ini. This is an example of what my inventory looks like. In the configuration file, I have place my server into a category called "app".
At the bottom you can see that we setup the user and where our ssh-key pair can be located by ansible.
# inventory file: hosts
[app]
34.129.197.131
[all:vars]
ansible_user=jeremy
ansible_ssh_private_key_file=~/.ssh/my-gcp-key
Once we have our inventory setup, we can simply run it.
ansible -i inventory.ini -m ping app
We have successfully execute an adhoc ansible command.
You can also try running shell ad hoc command
ansible -i inventory.ini -m shell -a "echo hello" app
Comments