Ansible, App Pool, and Specific Identity

Is it possible to create an IIS Application Pool that uses a custom identity with Ansible?

I asked the question on the Ansible forums and got the following response.

  1. Create the Application Pool first using “win_iis_webapppool
  2. Then switch the pools Identity using module “win_command” and the “appcmd.exe” command.

Here are the results and notes from my implementation.

  1. Create playbook that creates pool and then updates (Example below)

    • – hosts: windows
      remote_user: buildadmin
      – name: Create new application pool
      name: “{{ apppool }}”
      state: started
      attributes: ‘managedRuntimeVersion:v4.0|autoStart:false’
      – name: Update application pool identity
      win_command: ‘C:\Windows\System32\inetsrv\appcmd set config /section:applicationPools /[name=”{{ apppool }}”].processModel.identityType:SpecificUser /[name=”{{ apppool }}”].processModel.userName:buildadmin /[name=”{{ apppool }}”].processModel.password:myPassword’
  2. Run the playbook against my windows machines with a command line variable
    • ansible-playbook -v installWebsiteApplication.yml -i hosts –extra-vars “apppool=devopsWebsite_1_1_2017”