Ansible - passing values entered on command line to a playbook

Greetings all –

Have been learning Ansible v2.8.4 for work as we are going down the automation path converting our bare-metal servers to VM’s. Our project right now is to create the various Ansible inventories & playbooks to build our VM’s and install the necessary software products for our environments, which are a mixture of Windows & Linux (of the Red Hat flavor).

We have a handful of sysadmins who will be running these scripts and for auditing & security purposes, we need to keep track of who creates & installs what.

My playbook contains ‘var-prompt’ statements that ask for our vCenter and sysadmin credentials before proceeding. When running the role to create my VM, I have to disable ‘gather_facts’ in order to use the sysadmin ID & password values from the ‘var-prompt’ statements to build my VM. But when I re-enable ‘gather_facts’ after my VM is created, I am no longer able to use those same variables since they are getting cleared out.

We are using AD for all our login authentication and I’m trying to come up with a way to capture user ID values entered from the command line and pass them to global variables for use whenever our admins are running any Ansible playbooks. This will allow us to add the user ID to various comments when creating VM’s or adding software packages and satisfy the requirements of our auditing department. Also, I would like to use the sysadmin values as input to my ‘Linux_join_AD’ role since the admin running the playbook will have the proper permissions to run the ‘realm join’ command.

Example of my playbook:

  • hosts: [linux-all]
      gather_facts: false
      become: true

vars_prompt:

  • name: vcenter_address_prompt
      prompt: “vcenter_address_prompt”
      private: no

  • name: vcenter_user_name_prompt
      prompt: “vcenter_user_name_prompt”
      private: no

  • name: vcenter_password_prompt
      prompt: “vcenter_password_prompt”
      private: yes

  • name: local_admin_password
      prompt: “local_admin_password”
      private: yes

roles:

  • vmware-createVM2

  • hosts: [linux-all]
      gather_facts: true
      become: true

roles:

  • vmware-createVM2
  • linux_filesystem
  • linux_ssh_banners
  • install_Zabbix_agent
  • required_yum_packages
  • rhel7_firewalld
  • Linux_join_AD

Is it possible to pass values entered on the command-line to global variables for use in various Ansible plays??

Thanks for your time!!!