run an ansible playbook in a host passed as param

1 – create the playbook

cat > play.yml <<EOF
---
- name: 'set host'
  hosts: "{{ target }}"
  gather_facts: false

  tasks:

  - name: 'show running host'
    debug:
      msg: "running on: {{ inventory_hostname }}"
EOF

2 – run the playbook in a specific host

 ansible-playbook play.yml -e target=localhost

to run in multiple hosts

 ansible-playbook play.yml -e target=localhost,192.168.0.7

Leave a comment