Role
<Ansible Dir>/roles/common.sethostname/tasks/main.yml
- name: Set hostname
hostname: name={{ inventory_hostname }}
Playbook
- name: Update hostname
hosts: all
become: yes
roles:
- common.hostname
Execute
ansible-playbook -i <inventory file> <playbook file>