Skip to content

Example 9

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: user_password
      prompt: "Enter your password"
      encrypt: sha256_crypt
      confirm: true
      salt_size: 7
  tasks:
    - debug:
        msg: "This is the encrypted password: {{ user_password }}"

Tip

For additional security the variables stored with vars_prompt can be encrypted.

Execute the following command

ansible-playbook playbook.yml

Bonus round

Check the official documentation for vars_prompt and try out other encryption algorithms.