savoirfairelinux.nexus3-oss

Ansible 角色:Nexus 3 OSS

该角色用于在 CentOS/RHEL 上安装和配置 Nexus 存储库管理器 OSS 版本 3.x。

所有配置可以通过重新运行角色进行更新,除了与 blobstores 相关的设置,blobstores 在 Nexus 中是不可变的。

要求

  • 该角色仅在 CentOS 7 和 Ubuntu 16.04(Xenial)上进行过测试。
  • Oracle Java 8(必需)
  • Apache HTTPD(可选,用于设置 SSL 反向代理)

(见下文 依赖 部分以获取在 Galaxy 上匹配的角色)

角色变量

Ansible 变量及其默认值(见 default/main.yml):

nexus_version: '3.1.0-04'
nexus_timezone: 'UTC'
nexus_package: "nexus-{{ nexus_version }}-unix.tar.gz"

要安装的 Nexus 版本和包,详见可用版本 https://www.sonatype.com/download-oss-sonatypenexus_timezone 是 Java 时区名称,可以与下面的 nexus_scheduled_tasks cron 表达式结合使用。

nexus_download_dir: '/tmp'

目标机器上下载 Nexus 包的目录。

nexus_default_port: 8081
nexus_default_context_path: '/'

Java Nexus 进程的端口和上下文路径。设置 nexus_default_context_path 时必须保留尾部斜杠,例如:nexus_default_context_path: '/nexus/'

nexus_os_group: 'nexus'
nexus_os_user: 'nexus'

用来拥有 Nexus 文件和运行服务的用户和组,如果不存在,将由角色创建。

nexus_installation_dir: '/opt'
nexus_data_dir: '/var/nexus'
nexus_tmp_dir: '/tmp/nexus'

Nexus 目录,nexus_installation_dir 包含已安装的可执行文件,nexus_data_dir 包含所有配置、存储库和上传的工件。注意:可以配置自定义 blobstores 路径以外的 nexus_data_dir,见下文 nexus_blobstores

nexus_admin_password: 'changeme'

要设置的 'admin' 账户密码。注意:此角色尚未实现首次安装后更改管理员密码的功能。

nexus_anonymous_access: false

允许 匿名访问 Nexus。

public_hostname: 'nexus.vm'

Nexus 实例向其客户端可访问的完全限定域名。

nexus_branding_header: ""
nexus_branding_footer: "上次配置 {{ ansible_date_time.iso8601 }}"

页眉和页脚品牌,可以包含 HTML。

httpd_setup_enable: false
httpd_ssl_certificate_file: 'files/nexus.vm.crt'
httpd_ssl_certificate_key_file: 'files/nexus.vm.key'

设置 SSL 反向代理,需要安装 httpd。注意:当 httpd_setup_enable 设置为 true 时,Nexus 绑定到 127.0.0.1:8081,因此 无法 从外部 IP 直接访问 HTTP 端口 8081。

ldap_connections: []

LDAP 连接 设置,每项如下:

  - ldap_name: '我的公司 LDAP' # 用作更新 LDAP 配置的键
    ldap_protocol: 'ldaps' # ldap 或 ldaps
    ldap_hostname: 'ldap.mycompany.com'
    ldap_port: 636
    ldap_search_base: 'dc=mycompany,dc=net'
    ldap_auth: 'none' # 或 simple
    ldap_auth_username: '用户名' # 如果认证方式 = simple
    ldap_auth_password: '密码' # 如果认证方式 = simple
    ldap_user_base_dn: 'ou=users'
    ldap_user_filter: '(cn=*)' # (可选)
    ldap_user_object_class: 'inetOrgPerson'
    ldap_user_id_attribute: 'uid'
    ldap_user_real_name_attribute: 'cn'
    ldap_user_email_attribute: 'mail'
    ldap_user_subtree: false
    ldap_map_groups_as_roles: false
    ldap_group_base_dn: 'ou=groups'
    ldap_group_object_class: 'posixGroup'
    ldap_group_id_attribute: 'cn'
    ldap_group_member_attribute: 'memberUid'
    ldap_group_member_format: '${username}'
    ldap_group_subtree: false

示例 LDAP 配置用于匿名认证(匿名绑定),这是 "最小" 配置:

  - ldap_name: '最简单的 LDAP 配置'
    ldap_protocol: 'ldaps'
    ldap_hostname: 'annuaire.mycompany.com'
    ldap_search_base: 'dc=mycompany,dc=net'
    ldap_port: 636
    ldap_user_id_attribute: 'uid'
    ldap_user_real_name_attribute: 'cn'
    ldap_user_email_attribute: 'mail'
    ldap_user_object_class: 'inetOrgPerson'

示例 LDAP 配置用于简单认证(使用 DSA 账户):

  - ldap_name: '使用 DSA 的 LDAP 配置'
    ldap_protocol: 'ldaps'
    ldap_hostname: 'annuaire.mycompany.com'
    ldap_port: 636
    ldap_auth: 'simple'
    ldap_auth_username: 'cn=mynexus,ou=dsa,dc=mycompany,dc=net'
    ldap_auth_password: "{{ vault_ldap_dsa_password }}" # 最好将密码保存在 ansible vault 中
    ldap_search_base: 'dc=mycompany,dc=net'
    ldap_user_base_dn: 'ou=users'
    ldap_user_object_class: 'inetOrgPerson'
    ldap_user_id_attribute: 'uid'
    ldap_user_real_name_attribute: 'cn'
    ldap_user_email_attribute: 'mail'
    ldap_user_subtree: false

示例 LDAP 配置用于简单认证(使用 DSA 账户) + 映射组为角色:

  - ldap_name: '使用 DSA 的 LDAP 配置'
    ldap_protocol: 'ldaps'
    ldap_hostname: 'annuaire.mycompany.com'
    ldap_port: 636
    ldap_auth: 'simple'
    ldap_auth_username: 'cn=mynexus,ou=dsa,dc=mycompany,dc=net'
    ldap_auth_password: "{{ vault_ldap_dsa_password }}" # 最好将密码保存在 ansible vault 中
    ldap_search_base: 'dc=mycompany,dc=net'
    ldap_user_base_dn: 'ou=users'
    ldap_user_object_class: 'inetOrgPerson'
    ldap_user_id_attribute: 'uid'
    ldap_user_real_name_attribute: 'cn'
    ldap_user_email_attribute: 'mail'
    ldap_map_groups_as_roles: true
    ldap_group_base_dn: 'ou=groups'
    ldap_group_object_class: 'groupOfNames'
    ldap_group_id_attribute: 'cn'
    ldap_group_member_attribute: 'member'
    ldap_group_member_format: 'uid=${username},ou=users,dc=mycompany,dc=net'
    ldap_group_subtree: false
nexus_privileges:
  - name: all-repos-read # 用作更新权限的键
    description: '对所有存储库的读和浏览访问'
    repository: '*'
    actions: # 可以是 add, browse, create, delete, edit, read 或 *(所有)
      - read
      - browse

要设置的 权限 列表。项与以下默认值结合:

    _nexus_privilege_defaults:
      type: repository-view
      format: maven2
      actions:
        - read
    nexus_roles:
      - id: Developpers # 可映射到 LDAP 组 ID,也用作更新角色的键
        name: developers
        description: 所有开发人员
        privileges:
          - nx-search-read
          - all-repos-read
        roles: [] # 对其他角色名称的引用

要设置的 角色 列表。

nexus_local_users: []

要在 Nexus 中创建的本地(非 LDAP)用户/帐户,每项如下:

  - username: jenkins # 用作更新的键
    first_name: Jenkins
    last_name: CI
    email: [email protected]
    password: "s3cr3t"
    roles:
      - developers # 角色 ID
nexus_delete_default_repos: false

从 Nexus 安装的初始默认配置中删除存储库。此步骤仅在首次安装时执行(当检测到 nexus_data_dir 为空时)。

nexus_delete_default_blobstore: false

从 Nexus 安装的初始默认配置中删除默认 blobstore。只有当 nexus_delete_default_repos: true 且所有配置的存储库(见下文)具有明确的 blob_store: custom 时,这可以执行。此步骤仅在首次安装时执行(当检测到 nexus_data_dir 为空时)。

nexus_blobstores: []
# 示例 blobstore 项:
# - name: separate-storage
#   path: /mnt/custom/path

要创建的 Blobstores 。一旦初始创建,blobstore 路径和存储库 blobstore 将无法更新(在重新配置时,任何更新都将被忽略)。

nexus_scheduled_tasks: []
# 示例任务以压缩 blobstore:
# - name: compact-blobstore
#   cron: '0 0 22 * * ?'
#   typeId: blobstore.compact
#   taskProperties:
#     blobstoreName: 'default' # 所有任务属性都以字符串形式存储在 Nexus 内部

要设置的 计划任务typeId 和特定于任务的 taskProperties 可以从 org.sonatype.nexus.scheduling.TaskDescriptorSupport 的 Java 类型层次结构中推断,也可以通过在手动配置任务时查看浏览器的 AJAX 请求来发现。

nexus_repos_maven_proxy:
  - name: central
    remote_url: 'https://repo1.maven.org/maven2/'
    layout_policy: permissive
  - name: jboss
    remote_url: 'https://repository.jboss.org/nexus/content/groups/public-jboss/'
# 带有登录名/密码的示例:
# - name: secret-remote-repo
#   remote_url: 'https://company.com/repo/secure/private/go/away'
#   remote_username: 'username'
#   remote_password: 'secret'

Maven 代理存储库 配置。

nexus_repos_maven_hosted:
  - name: private-release
    version_policy: release
    write_policy: allow_once

Maven 托管存储库 配置。

nexus_repos_maven_group:
  - name: public
    member_repos:
      - central
      - jboss

Maven 组存储库 配置。

这三种存储库类型与以下默认值结合:

    _nexus_repos_maven_defaults:
      blob_store: default # 注意:一旦创建存储库后无法更新
      strict_content_validation: true
      version_policy: release # release, snapshot 或 mixed
      layout_policy: strict # strict 或 permissive
      write_policy: allow_once # allow_once 或 allow

Docker、Pypi、原始、Rubygems、Bower、NPM 和 Git-LFS 存储库类型: 见 defaults/main.yml 以获取这些选项:

  nexus_config_pypi: false
  nexus_config_docker: false
  nexus_config_raw: false
  nexus_config_rubygems: false
  nexus_config_bower: false
  nexus_config_npm: false
  nexus_config_gitlfs: false

除非您从 playbook / group_var / cli 覆盖它们,否则这些默认值均为 false,这些都利用与 Maven 相同的机制。

依赖关系

该角色需要 Ansible 2.1 或更高版本。

Java 和 httpd 要求可以通过以下 Galaxy 角色满足:

示例 Playbook

---
- name: Nexus
  hosts: nexus
  become: yes

  vars:
    nexus_version: '3.1.0-04'
    nexus_timezone: 'Canada/Eastern'
    nexus_admin_password: "{{ vault_nexus_admin_password }}"
    httpd_server_name: 'nexus.vm'
    httpd_setup_enable: true
    httpd_ssl_certificate_file: "{{ vault_httpd_ssl_certificate_file }}"
    httpd_ssl_certificate_key_file: "{{ vault_httpd_ssl_certificate_key_file }}"
    ldap_connections:
      - ldap_name: '公司 LDAP'
        ldap_protocol: 'ldaps'
        ldap_hostname: 'ldap.company.com'
        ldap_port: 636
        ldap_search_base: 'dc=company,dc=net'
        ldap_user_base_dn: 'ou=users'
        ldap_user_object_class: 'inetOrgPerson'
        ldap_user_id_attribute: 'uid'
        ldap_user_real_name_attribute: 'cn'
        ldap_user_email_attribute: 'mail'
        ldap_group_base_dn: 'ou=groups'
        ldap_group_object_class: 'posixGroup'
        ldap_group_id_attribute: 'cn'
        ldap_group_member_attribute: 'memberUid'
        ldap_group_member_format: '${username}'
    nexus_privileges:
      - name: all-repos-read
        description: '对所有存储库的读和浏览访问'
        repository: '*'
        actions:
          - read
          - browse
      - name: company-project-deploy
        description: '部署到 company-project'
        repository: company-project
        actions:
          - add
          - edit
    nexus_roles:
      - id: Developpers # 映射到 LDAP 组
        name: developers
        description: 所有开发人员
        privileges:
          - nx-search-read
          - all-repos-read
          - company-project-deploy
        roles: []
    nexus_local_users:
      - username: jenkins # 用作更新的键
        first_name: Jenkins
        last_name: CI
        email: [email protected]
        password: "s3cr3t"
        roles:
          - Developpers # 这里是角色 ID
    nexus_blobstores:
      - name: company-artifacts
        path: /var/nexus/blobs/company-artifacts
    nexus_scheduled_tasks:
      - name: compact-blobstore
        cron: '0 0 22 * * ?'
        typeId: blobstore.compact
        taskProperties:
          blobstoreName: 'company-artifacts'
    nexus_repos_maven_proxy:
      - name: central
        remote_url: 'https://repo1.maven.org/maven2/'
        layout_policy: permissive
      - name: alfresco
        remote_url: 'https://artifacts.alfresco.com/nexus/content/groups/private/'
        remote_username: 'secret-username'
        remote_password: "{{ vault_alfresco_private_password }}"
      - name: jboss
        remote_url: 'https://repository.jboss.org/nexus/content/groups/public-jboss/'
      - name: vaadin-addons
        remote_url: 'https://maven.vaadin.com/vaadin-addons/'
      - name: jaspersoft
        remote_url: 'https://jaspersoft.artifactoryonline.com/jaspersoft/jaspersoft-repo/'
        version_policy: mixed
    nexus_repos_maven_hosted:
      - name: company-project
        version_policy: mixed
        write_policy: allow
        blob_store: company-artifacts
    nexus_repos_maven_group:
      - name: public
        member_repos:
          - central
          - jboss
          - vaadin-addons
          - jaspersoft

  roles:
    - role: ansiblebit.oracle-java
      oracle_java_set_as_default: yes
    - role: geerlingguy.apache
      apache_create_vhosts: no
    - role: savoirfairelinux.nexus3-oss

许可证

GNU GPLv3

作者信息

请见 https://github.com/savoirfairelinux/ansible-nexus3-oss

关于项目

Nexus Repository Manager 3.x for RedHat/CentOS

安装
ansible-galaxy install savoirfairelinux.nexus3-oss
许可证
gpl-3.0
下载
24.2k
拥有者
Savoir-faire Linux