I don’t want my password in clear text in playbooks so this how to encrypt the password in AWX and injecting into the playbook.

AWX is similar to ansible tower but open source, basically a GUI for ansible.

The playbook I am injecting my username password into is deploying a virtual machine from a template.

Tasks

  1. Create Credential Types
  2. Create Credential
  3. Add to template

Here is my code, bold is my username and password

- name: Create a VM from a template
  hosts: localhost
  gather_facts: true
  vars:
    datacenter_name: "dc1"
  tasks:
    - name: Clone the template
      vmware_guest:
        hostname: "vc1.vmware.local"
        username: "{{ lookup('env', 'VMWARE_USER') }}"
        password: "{{ lookup('env', 'VMWARE_PASS') }}"
        validate_certs: False
        name: ansible-test-vm1
        template: ansible-template 
        datacenter: "{{ datacenter_name }}"
        folder: /dc1/vm
        state: poweredon
        cluster: cl1
        wait_for_ip_address: no

Credential Types creation

Input configuration in YAML
fields:
  - id: username
    type: string
    label: vCenter Username
  - id: password
    type: string
    label: vCenter Password
    secret: true
Injector configuration in YAML
env:
  VMWARE_PASS: '{{ password }}'
  VMWARE_USER: '{{ username }}'

Create Credential

Add to template (template is basically the job or task your running)

By Kad

Leave a Reply

Your email address will not be published. Required fields are marked *