community.windows.win_psrepository_copy (2.2.0) — module

Copies registered PSRepositories to other user profiles

| "added in version" 1.3.0 of community.windows"

Authors: Brian Scholer (@briantist)

Install collection

Install with ansible-galaxy collection install community.windows:==2.2.0


Add to requirements.yml

  collections:
    - name: community.windows
      version: 2.2.0

Description

Copies specified registered PSRepositories to other user profiles on the system.

Can include the C(Default) profile so that new users start with the selected repositories.

Can include special service accounts like the local SYSTEM user, LocalService, NetworkService.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Copy the current user's PSRepositories to all non-service account profiles and Default profile
  community.windows.win_psrepository_copy:
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Copy the current user's PSRepositories to all profiles and Default profile
  community.windows.win_psrepository_copy:
    exclude_profiles: []
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Copy the current user's PSRepositories to all profiles beginning with A, B, or C
  community.windows.win_psrepository_copy:
    profiles:
      - 'A*'
      - 'B*'
      - 'C*'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Copy the current user's PSRepositories to all profiles beginning B except Brian and Brianna
  community.windows.win_psrepository_copy:
    profiles: 'B*'
    exclude_profiles:
      - Brian
      - Brianna
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Copy a specific set of repositories to profiles beginning with 'svc' with exceptions
  community.windows.win_psrepository_copy:
    name:
      - CompanyRepo1
      - CompanyRepo2
      - PSGallery
    profiles: 'svc*'
    exclude_profiles: 'svc-restricted'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Copy repos matching a pattern with exceptions
  community.windows.win_psrepository_copy:
    name: 'CompanyRepo*'
    exclude: 'CompanyRepo*-Beta'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Copy repositories from a custom XML file on the target host
  community.windows.win_psrepository_copy:
    source: 'C:\data\CustomRepostories.xml'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
### A sample workflow of seeding a system with a custom repository

# A playbook that does initial host setup or builds system images

- name: Register custom respository
  community.windows.win_psrepository:
    name: PrivateRepo
    source_location: https://example.com/nuget/feed/etc
    installation_policy: trusted
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Ensure all current and new users have this repository registered
  community.windows.win_psrepository_copy:
    name: PrivateRepo
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# In another playbook, run by other users (who may have been created later)

- name: Install a module
  community.windows.win_psmodule:
    name: CompanyModule
    repository: PrivateRepo
    state: present

Inputs

    
name:
    default:
    - '*'
    description:
    - The names of repositories to copy.
    - Names are interpreted as wildcards.
    elements: str
    type: list

source:
    default: '%LOCALAPPDATA%\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml'
    description:
    - The full path to the source repositories XML file.
    - Defaults to the repositories registered to the current user.
    type: path

exclude:
    description:
    - The names of repositories to exclude.
    - Names are interpreted as wildcards.
    - If a name matches both an include (I(name)) and I(exclude), it will be excluded.
    elements: str
    type: list

profiles:
    default:
    - '*'
    description:
    - The names of user profiles to populate with repositories.
    - Names are interpreted as wildcards.
    - The C(Default) profile can also be matched.
    - The C(Public) and C(All Users) profiles cannot be targeted, as PSRepositories are
      not loaded from them.
    elements: str
    type: list

exclude_profiles:
    default:
    - systemprofile
    - LocalService
    - NetworkService
    description:
    - The names of user profiles to exclude.
    - If a profile matches both an include (I(profiles)) and I(exclude_profiles), it will
      be excluded.
    - By default, the service account profiles are excluded.
    - To explcitly exclude nothing, set I(exclude_profiles=[]).
    elements: str
    type: list

See also