- hosts: '{{hosts}}' remote_user: root tasks: - name: rsync hosts lineinfile: dest: /etc/hosts line: "{{ item }}" with_items: - "10.104.159.56 elk" - "10.104.144.186 elk2" - "10.104.37.244 elk3" # ansible-playbook /etc/ansible/rsync_hosts.yml -e "hosts=java" --private-key=/etc/ansible/new_www.key