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


If you run into issue where you not able to connect (maybe after a server reboot), this could be due to ssh finger printing. Try to debug by ssh into your vm and see if it prompts you for password.

ssh -i ~/.ssh/my-gcp-key jeremy@34.129.28.4








Comments

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type