Automating Oracle Forms environment files configuration

Automating everything many times comes to a halt once you discover that specific applications or platforms do not support changes to be done using a command-line interface. One such application is Oracle Forms, even if you run the latest and greatest version of it.
This post is not to prove it different, but I instead consider it as an aid to those who want to dig a bit deeper.
In Forms, configurations are supposed to be made through Enterprise Manager and not manually. This includes editing files manually and also creating/copying env files. Forms runtime reads its environment parameters from the *.env files. If these files are created manually, it is not possible to manage these files through EM.
You can check 1223345.1 Doc ID at Oracle Support to find some clues about how to register manually created .env files to Enterprise Manager in Forms version 11g. It stays true for the 12c version as well. The sequence, namely, is:

  1. Get a backup copy of the manually created env file and delete it from the OS
  2. Go to EM, "Environment Configuration" page of forms and using "Duplicate File" button create a new copy of this file form default.env
  3. Shutdown WLS_Forms
  4. Copy the backup you get in step#1 above on top of the new file generated in step#2 above
  5. Start the WLS_Forms once more
  6. Logout from Enterprise Manager and Login back

OS changes and start/stop operations are easy to automate. But when it comes to creating a new copy of the default.env file, it's not easy to do it from a command line unless you know what MBean to call.
You can use FMW Control application to find the following MBean: oracle.forms:type=FormsSystemComponent,name=FORMSInstanceManager
This MBean allows performing operations with Forms environment files.
As an example, here is how you can create a wlst script template in Ansible that will help you with the handling of Oracle Forms using Ansible role:

connect('{{ admin_user }}','{{ admin_pwd }}',url='t3://{{ admin_host }}:{{ admin_port }}')

edit()
startEdit()
fBean=ObjectName('oracle.forms:type=FormsSystemComponent,name=FORMSInstanceManager')
operationName='duplicateConfigFile'
params = ["{{ server_name }}","formsapp","default.env","{{ env_file }}","Type_default.env"]
sign = ["java.lang.String","java.lang.String","java.lang.String","java.lang.String","java.lang.String"]
mbs.invoke(fBean, operationName, params, sign)
activate()

Knowledge of the right MBean together with Ansible tool will allow you to replace configuration process manual tasks with a simple playbook.