ansible-collections / ansible.windows

Windows core collection for Ansible
https://galaxy.ansible.com/ansible/windows
GNU General Public License v3.0
250 stars 168 forks source link

Resource 'AdcsCertificationAuthority' not found if use win_dsc #381

Closed patsevanton closed 2 years ago

patsevanton commented 2 years ago
ISSUE TYPE
COMPONENT NAME

win_dsc

ANSIBLE VERSION
ansible [core 2.12.7]
  config file = /home/user/github/infrastructure-as-a-code-example/pdc/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Apr  2 2022, 09:04:19) [GCC 11.2.0]
  jinja version = 3.0.3
  libyaml = True
COLLECTION VERSION
ansible.windows 1.10.0
CONFIGURATION
CALLBACKS_ENABLED(/home/user/github/infrastructure-as-a-code-example/pdc/ansible.cfg) = ['profile_tasks']
DEFAULT_GATHERING(/home/user/github/infrastructure-as-a-code-example/pdc/ansible.cfg) = smart
DEFAULT_STDOUT_CALLBACK(/home/user/github/infrastructure-as-a-code-example/pdc/ansible.cfg) = yaml
OS / ENVIRONMENT

Ubuntu 22.04 host Windows 2019 DC

STEPS TO REPRODUCE
- hosts: pdc
  roles:
    - role: justin_p.posh5
    - role: justin_p.wincom
    - role: justin_p.pdc
  post_tasks:
    - name: Install ADCS-Cert-Authority with sub features and management tools
      win_feature:
        name: ADCS-Cert-Authority
        state: present
        include_management_tools: yes
      register: win_feature

    - name: Install ADCS-Enroll-Web-Pol with sub features and management tools
      win_feature:
        name: ADCS-Enroll-Web-Pol
        state: present
        include_management_tools: yes
      register: win_feature

    - name: Install ADCS-Web-Enrollment with sub features and management tools
      win_feature:
        name: ADCS-Web-Enrollment
        state: present
        include_management_tools: yes
      register: win_feature

    - name: reboot if installing Adcs-Cert-Authority feature requires it
      win_reboot:
      when: win_feature.reboot_required

    - name: Configure AdcsCertificationAuthority Powershell DSC
      win_dsc:
        resource_name: AdcsCertificationAuthority
        IsSingleInstance: 'Yes'
        CAType: 'EnterpriseRootCA'
        CryptoProviderName: 'RSA#Microsoft Software Key Storage Provider'
        KeyLength: 2048
        HashAlgorithmName: 'SHA256'
        ValidityPeriod: 'Years'
        ValidityPeriodUnits: 99
EXPECTED RESULTS
ACTUAL RESULTS
TASK [Configure AdcsCertificationAuthority Powershell DSC] *************************************************************************************
task path: /home/user/github/infrastructure-as-a-code-example/pdc/playbook.yml:43 ********** 
redirecting (type: modules) ansible.builtin.win_dsc to ansible.windows.win_dsc
redirecting (type: modules) ansible.builtin.win_dsc to ansible.windows.win_dsc
Using module file /usr/lib/python3/dist-packages/ansible_collections/ansible/windows/plugins/modules/win_dsc.ps1
Pipelining is enabled.
<51.250.30.189> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO xx.xx.xx.xx
EXEC (via pipeline wrapper)
fatal: [pdc]: FAILED! => changed=false 
  msg: Resource 'AdcsCertificationAuthority' not found.
jborean93 commented 2 years ago

In this case AdcsCertificationAuthority is a custom DSC resource that is provided through the ActiveDirectoryCSDsc module and not the builtin ADCS-Cert-Authority feature. The latter installs the Install-AdcsCertificationAuthority cmdlet which you can call through ansible.windows.win_shell or ansible.windows.win_powershell but the DSC stuff still needs to be installed separately through something like `community.windows.win_psmodule