Mr Cheng bio photo

Mr Cheng

Ansible

ad hoc mode

In ansible, you’re executing a set of commands against a set of hosts where hosts are defined in another file, for example ./hosts:

echo "[web-servers]
web1
web2
web[4:7] > /.hosts"

Run it like this: ansible -m ping -i ./hosts web-servers

playbook mode

here’s a playbook example using the same host inventory file. Run it like this: ansible-playbook test.yml -i ./hosts

- name: example 2
  hosts: web-servers
  tasks:
    - debug:
        msg: "{{ item }}"
      with_items: "{{ web-servers }}"