Ansible Collection - c2platform.wincore
Categories:
GitLab: c2platform/rws/ansible-collection-wincore
C2 Platform generic roles for MS Windows that are used by all or some other roles. These roles typically don’t create services / processes on target node but are dependencies e.g. packages required by those roles. Or these roles help with Ansible provisioning for example offers generic Ansible modules, filters etc.
Roles
- download manage downloads.
- win manage users, features, services, scheduled_tasks, packages ( chocolatey), files, directories etc.
- ad Active Directory ( AD) management using microsoft.ad Ansible collection.
Plugins
Module plugins:
win_certificate
The c2platform.wincore.win_certificate
module allows you to create TLS/SSL
certificates. It provides four variables: dns_name
, validity_days
(default:
365
), store_location
(default: Cert:\LocalMachine\My
), and state
(default: present
). The example below demonstrates how to create a TLS/SSL
certificate and use it to configure an IIS HTTPS Binding on port 443 using
module community.windows.win_iis_webbinding
.
- name: Manage certificate
c2platform.wincore.win_certificate:
dns_name: "{{ ansible_hostname }}"
validity_days: 3650
state: present
# tmp_file_path: D:\Temp\ExportedCertificate.cer
register: _cert
- name: Add a HTTPS binding
community.windows.win_iis_webbinding:
name: "{{ arcgis_webadaptor_ssl_certificate_iis_web_site_name }}"
protocol: https
port: 443
ip: '*'
certificate_hash: "{{ _cert.thumbPrint }}"
state: present
when: '"thumbPrint" in _cert'
win_package_facts
To retrieve a list of installed packages and store it in the Ansible fact
installed_packages
, you can utilize the c2platform.wincore.win_package_facts
module. Below is an example that demonstrates how to use this module to install
Microsoft Web Deploy, but only if it is not already installed.
- name: Get Installed packages
c2platform.wincore.win_package_facts:
- name: Display Installed Packages
debug:
var: ansible_facts.installed_packages
- name: Install WebDeploy for IIS
ansible.windows.win_package:
path: '{{ arcgis_webadaptor_temp_dir["path"] }}\{{ arcgis_webadaptor_versions[arcgis_webadaptor_version]["webdeploy"]["url"] | basename }}'
arguments: 'ADDLOCAL=ALL LicenseAccepted="0"'
state: present
when: '"Microsoft Web Deploy 3.6" not in ansible_facts.installed_packages'
In this example, the win_package_facts
module is used to collect information
about installed packages on the Windows system and store it in the
installed_packages
fact. Additionally, it demonstrates how to conditionally
install Microsoft Web Deploy only if it is not already present in the list of
installed packages.
Filters
download_file_path
When leveraging the download
role for downloading tasks,
the download_file_path
filter proves invaluable for obtaining the precise
download path.
Consider the following comparison:
Instead of:
fme_flow_installer_path: '{{ fme_flow_temp_dir["path"] }}\{{ fme_flow_versions[fme_flow_version]["url"] | basename }}'
Opt for:
fme_flow_installer_path: >-
{{ fme_flow_versions[fme_flow_version]["url"]
| c2platform.wincore.download_file_path(fme_flow_temp_dir["path"]) }}
download_extract_folder
When utilizing the download
role to manage downloads and
unzip files, the download_extract_folder
filter is your go-to solution for
retrieving the path of the extracted contents.
For instance:
fme_flow_extraction_path: "{{ fme_flow_installer_path.removesuffix('.' + fme_flow_installer_extname) }}"
Opt for the cleaner alternative:
fme_flow_extraction_path: >-
{{ fme_flow_versions[fme_flow_version]["url"]
| c2platform.wincore.download_extract_folder(fme_flow_temp_dir["path"]) }}
This revised syntax not only improves readability but also ensures a more efficient and maintainable configuration.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.