https://github.com/geerlingguy/ansible-for-kubernetes


HOW ANSIBLE KNOWS WHERE TO RUN THE PLAYBOOKS?

By default Ansible uses SSH to connect to remote hosts and run commands.

Ansible uses the SSH protocol to connect to remote hosts, and it authenticates using SSH keys instead of a password. This provides a secure and convenient way to connect to remote hosts without having to enter a password each time.

In Ansible, the target hosts that a playbook should run on are specified in an inventory file. The inventory file is a simple text file that lists the hostnames or IP addresses of the systems that Ansible should manage.

By default, Ansible will look for an inventory file in the location **/etc/ansible/hosts** , but you can specify a different location using the **-i**** **option when running the ansible-playbook command.


Here is an example of using Ansible to set up a Docker container:

- name: Install Docker
  package:
    name: docker-ce
    state: present
 
- name: Start and enable Docker service
  service:
    name: docker
    state: started
    enabled: true
 
- name: Pull Docker image
  command: docker pull nginx:latest
 
- name: Run Docker container
  command: docker run --name nginx -d -p 80:80 nginx:latest

🌱 Back to Garden