Skip to content

Example 8

hosts.yml

centos:
  hosts:
    provisioner:
      ansible_connection: local
    centos1:
      ansible_host: '192.168.77.22'
ubuntu:
  hosts:
    ubuntu1:
      ansible_host: '192.168.77.23'

playbook.yml

- name: Example playbook
  hosts: centos1
  gather_facts: false
  vars_prompt:
    - name: first_name
      prompt: "Enter your first name"
      private: false
  tasks:
    - debug:
        msg: "My first name is {{ first_name }}"

Tip

You can use the vars_prompt directive to assign variables in runtime by creating a user prompt. Adding the private: false directive to the prompt makes the input visible.

Execute the following command

ansible-playbook playbook.yml

Bonus round

Remove the private directive and run the command again. Notice the change in behavior"