pogosoftware.nexus3_oss
Ansible 角色: Nexus 3 OSS
这个角色用于安装和配置 Nexus Repository Manager OSS 版本 3.x。
所有配置都可以通过重新运行角色进行更新,但与 blobstores 相关的设置是不可变的。
目录
注意: 从 ansible galaxy 网站查看时,目录链接不会正常工作。 在 GitHub 上查看
(使用 gh-md-toc 创建)
历史 / 贡献
该角色是 savoirfairelinux 发布的 ansible-nexus3-oss 的一个分支,因为他们宣布停止维护。您可以在原存储库中查看以下问题以获取解释:
- https://github.com/savoirfairelinux/ansible-nexus3-oss/issues/36
- https://github.com/savoirfairelinux/ansible-nexus3-oss/issues/38
我们感谢原作者所做的工作。
要求
- 相对较新的 ansible 版本。我们在维护/开发期间遵循 ansible 版本,并在需要时利用新功能(并更新 meta/main.yml 以反映最低版本)
- 兼容的操作系统。此角色通过 molecule 在 travis CI 上针对 CentOS 8、Ubuntu Bionic(18.04)和 Debian Buster 进行测试。其他 molecule 场景可以在 CentOS 7、Ubuntu Xenial(16.04)和 Debian Stretch 上本地运行
- 目标机器上必须安装 rsync(在运行 ansible 的主机上不需要)
- 运行 playbook 的主机需要安装
jmespath
库(这是json_query
过滤器所需)。参见requirements.txt
- Java 8(强制要求)
- Oracle 宣布 Java 8 已经停止支持。Sonatype 现在推荐使用 openjdk8
- 有关更多信息,请参见 nexus3 系统要求
- Apache HTTPD(可选)
-用于设置 SSL 反向代理
- 必须在您的配置中启用以下模块: mod_ssl、mod_rewrite、mod_proxy、mod_proxy_http、mod_headers。
(请参见下面的 依赖关系 小节,以获取与 galaxy 中的角色匹配的信息)
角色变量
Ansible 变量及其默认值(请参见 default/main.yml
):
一般变量
nexus_version: ''
nexus_timezone: 'UTC'
nexus_download_url: "http://download.sonatype.com/nexus/3"
# nexus_download_ssl_verify: <unset>
# nexus_version_running: <unset>
该角色将默认安装最新的 nexus 版本。您可以通过设置 nexus_version
变量来固定版本。可用版本请查看 https://www.sonatype.com/download-oss-sonatype。
如果您固定了版本并将其更改为其他版本,则该角色将尝试升级您的安装。
确保在发布历史中更改为后续版本。降级将失败(除非您使用 nexus_purge
特殊变量 重新安装)。
如果您不固定版本并在现有安装上运行角色,则将使用当前安装的版本(检测目标为 {{ nexus_installation_dir}}/nexus-latest
)。如果您想升级 nexus,您必须在 ansible-playbook 命令行上传递特殊变量 nexus_upgrade=true
。
请参见 将 nexus 升级到最新版本
您必须确保使用比已安装的版本更高的版本,以避免使用在已安装版本中不可用的功能(例如,yum 托管的库对于 nexus < 3.8.0 或 Git LFS 库对于 nexus < 3.3.0 等)。
nexus_timezone
是 Java 时区名称,可以与下面的 nexus_scheduled_tasks
cron 表达式结合使用。
您可以通过调整 nexus_download_url
修改软件包的下载网站(例如,闭环环境,您网络中的代理/缓存...)。在这种情况下,自动检测最新版本可能会失败,您需要固定下载的版本。如果您仍然希望利用自动检测最新版本,调用 <your_custom_location>/latest-unix.tar.gz
必须返回到您缓存/代理中的最新可用版本的 HTTP 302 重定向。如果您的下载位置使用带自签名证书的 https(或来自私有 PKI)并且您在验证时遇到问题(例如,角色中的下载错误),如果您完全信任目标,则可以设置 nexus_download_ssl_verify: false
。
nexus_version_running
是内部使用的变量。因此,绝对不应直接设置
它仅在 nexus 当前安装在主机上时存在,并将在运行角色之前注册当前版本。随后可以在您的 playbook 中使用(例如,用于升级通知电子邮件)。
下载 nexus 包的目录
nexus_download_dir: '/tmp'
目标机器上将下载 nexus 包的目录。
重要说明: 如果您打算定期运行角色以维护/配置您的 nexus 安装,您应确保下载的文件在运行之间持续存在。在 RHEL/CentOS 上,您特别应该将此目录更改为不会自动清除的位置。如果包文件没有持续存在,则会再次下载这可能会导致不必要的 nexus 重启。
Nexus 端口、上下文路径和侦听 IP
nexus_default_port: 8081
nexus_application_host: '{{ httpd_setup_enable | ternary("127.0.0.1", "0.0.0.0") }}'
nexus_default_context_path: '/'
Java nexus 进程的侦听端口/ip 及上下文路径。
- 侦听 IP/接口(即
nexus_application_host
)默认依赖于httpd_setup_enable
设置。 如果启用反向代理,Nexus 将只监听 localhost(127.0.0.1);如果没有,则监听所有配置的 IP(0.0.0.0)。您可以根据需要更改此设置(即,如果您安装自己的代理,则仅绑定到 127.0.0.1,而不是安装代理) nexus_default_context_path
必须在设置时保留尾部斜杠,例如:nexus_default_context_path: '/nexus/'
。
Nexus 操作系统用户和组
nexus_os_group: 'nexus'
nexus_os_user: 'nexus'
允许更改 nexus 用户的默认主目录。
Nexus 实例目录
nexus_installation_dir: '/opt'
nexus_data_dir: '/var/nexus'
nexus_tmp_dir: "{{ (ansible_os_family == 'RedHat') | ternary('/var/nexus-tmp', '/tmp/nexus') }}"
Nexus 目录。
nexus_installation_dir
包含已安装的可执行文件nexus_data_dir
包含所有配置、库和上传的工件。可以配置自定义 blobstore 路径,见下文的nexus_blobstores
。nexus_tmp_dir
包含所有临时文件。默认路径已从/tmp
移动,以克服与自动清理程序有关的问题。
Nexus JVM 内存设置
nexus_min_heap_size: "1200M"
nexus_max_heap_size: "{{ nexus_min_heap_size }}"
nexus_max_direct_memory: "2G"
这些是 Nexus 的默认值。请不要修改这些值, _除非您已阅读 nexus 系统要求的内存部分 _并且您了解自己在做什么。
作为第二个警告,这里摘取来自上述文档:
增加 JVM 堆内存超过推荐值以试图提高性能并不建议。这实际上可能会产生相反的效果,导致操作系统无谓地换页。
插件安装
nexus_plugin_urls: []
放置指向为您的 Nexus 版本构建的插件的 URL 列表。只支持 *.kar 包的安装。
上手向导
nexus_onboarding_wizard: false
控制当管理员用户首次登录时是否运行 nexus 上手向导。
管理员密码
nexus_admin_password: 'changeme'
要设置的 'admin' 账户密码。_这仅在首次安装时生效_。如果您想在之后使用角色更改密码,请参见 首次安装后更改管理员密码。
强烈建议不要在 playbook 中以明文形式保存密码,并使用 ansible-vault 加密(例如行内或单独文件加载 include_vars)
默认匿名访问
nexus_anonymous_access: false
允许对 nexus 的 匿名访问。
公共主机名
nexus_public_hostname: 'nexus.vm'
nexus_public_scheme: https
Nexus 实例将向其客户端提供的完全合格域名及协议。
该角色的 API 访问
nexus_api_hostname: localhost
nexus_api_scheme: http
nexus_api_validate_certs: "{{ nexus_api_scheme == 'https' }}"
nexus_api_context_path: "{{ nexus_default_context_path }}"
nexus_api_port: "{{ nexus_default_port }}"
这些变量控制角色如何与 nexus API 进行连接以进行配置。 仅适用于高级用法。您很可能不希望更改这些默认设置
品牌能力
nexus_branding_header: ""
nexus_branding_footer: "Last provisionned {{ ansible_date_time.iso8601 }}"
头部和底部品牌内容,可以包含 HTML。
审计能力
nexus_audit_enabled: false
Nexus 的 审计能力 默认关闭。您可以通过将此值改为 true
来开启。请注意,审计数据存储在 nexus 数据库中,跨重启持久化且不会自动轮换/清除。
反向代理设置
httpd_setup_enable: false
httpd_server_name: "{{ nexus_public_hostname }}"
httpd_default_admin_email: "[email protected]"
httpd_ssl_certificate_file: 'files/nexus.vm.crt'
httpd_ssl_certificate_key_file: 'files/nexus.vm.key'
# httpd_ssl_certificate_chain_file: "{{ httpd_ssl_certificate_file }}"
httpd_copy_ssl_files: true
设置 SSL 反向代理。
这需要安装 httpd。注意: 当 httpd_setup_enable
设置为 true
时,nexus 默认绑定到 127.0.0.1:8081,因此 无法直接通过外部 IP 在 HTTP 端口 8081 上访问(如果您想更改它,可以显式设置 nexus_application_host: 0.0.0.0
)
使用的默认主机名是 nexus_public_hostname
。如果出于某种原因需要不同的名称,可以将 httpd_server_name
设置为其他值。
使用 httpd_copy_ssl_files: true
(默认值),上面的证书必须存在于您的 playbook 目录中并将被复制到服务器并在 apache 中配置。 httpd_ssl_certificate_chain_file
是可选的,如果您不想配置链文件则必须保持 unset。
如果要在服务器上使用现有证书,请设置 httpd_copy_ssl_files: false
,并提供以下变量
# 这些指定在远程服务器文件系统中查找证书文件的位置。
httpd_ssl_cert_file_location: "/etc/pki/tls/certs/wildcard.vm.crt"
httpd_ssl_cert_key_location: "/etc/pki/tls/private/wildcard.vm.key"
# httpd_ssl_cert_chain_file_location: "{{ httpd_ssl_cert_file_location }}"
httpd_ssl_cert_chain_file_location
是可选的,如果您不想配置链文件,则必须保持 unset。
httpd_default_admin_email: "[email protected]"
设置 httpd 默认管理员电子邮件地址。
LDAP 配置
LDAP 连接和安全域默认是禁用的。
nexus_ldap_realm: false
ldap_connections: []
LDAP 连接 设置,每个项如下:
nexus_ldap_realm: true
ldap_connections:
- ldap_name: 'My Company LDAP' # 用作更新 LDAP 配置的键
ldap_protocol: 'ldaps' # ldap 或 ldaps
ldap_hostname: 'ldap.mycompany.com'
ldap_port: 636
ldap_use_trust_store: false # 是否使用 nexus 信任存储中的证书
ldap_search_base: 'dc=mycompany,dc=net'
ldap_auth: 'none' # 或 simple
ldap_auth_username: 'username' # 如果身份验证= simple
ldap_auth_password: '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 配置,用于匿名身份验证(匿名绑定),这也是“最小”配置:
nexus_ldap_realm: true
ldap_connection:
- ldap_name: 'Simplest LDAP config'
ldap_protocol: 'ldaps'
ldap_hostname: 'annuaire.mycompany.com'
ldap_search_base: 'dc=mycompany,dc=net'
ldap_port: 636
ldap_use_trust_store: false
ldap_user_id_attribute: 'uid'
ldap_user_real_name_attribute: 'cn'
ldap_user_email_attribute: 'mail'
ldap_user_object_class: 'inetOrgPerson'
示例 LDAP 配置,用于简单身份验证(使用 DSA 帐户):
nexus_ldap_realm: true
ldap_connections:
- ldap_name: 'LDAP config with DSA'
ldap_protocol: 'ldaps'
ldap_hostname: 'annuaire.mycompany.com'
ldap_port: 636
ldap_use_trust_store: false
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 帐户) + 将组映射为角色:
nexus_ldap_realm: true
ldap_connections
- ldap_name: 'LDAP config with DSA'
ldap_protocol: 'ldaps'
ldap_hostname: 'annuaire.mycompany.com'
ldap_port: 636
ldap_use_trust_store: false
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
示例 LDAP 配置,用于简单身份验证(使用 DSA 帐户) + 将组动态映射到角色:
nexus_ldap_realm: true
ldap_connections:
- ldap_name: 'LDAP config with DSA'
ldap_protocol: 'ldaps'
ldap_hostname: 'annuaire.mycompany.com'
ldap_port: 636
ldap_use_trust_store: false
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_map_groups_as_roles_type: 'dynamic'
ldap_user_memberof_attribute: 'memberOf'
权限
nexus_privileges:
- name: all-repos-read # 用作更新权限的键
# type: <one of application, repository-admin, repository-content-selector, repository-view, script or wildcard>
description: '对所有库的读取和浏览访问'
repository: '*'
actions: # 可以是 add、browse、create、delete、edit、read 或 *(所有)
- read
- browse
设置的 权限 列表。请查看文档和 GUI,检查根据权限类型应该设置哪些变量。
这些项目与以下默认值组合:
_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: []
# - username: jenkins # 用作更新键
# state: present # 缺省值如省略,使用 'absent' 删除用户
# first_name: Jenkins
# last_name: CI
# email: [email protected]
# password: "s3cr3t"
# roles:
# - developers # 角色 ID
要在 nexus 中创建的本地(非 LDAP)用户/账户列表。状态 absent
将在用户存在时将其删除。
nexus_ldap_users: []
# - username: j.doe
# state: present
# roles:
# - "nx-admin"
LDAP 用户/角色映射。状态 absent
将从现有用户中删除角色(如果已经存在)。不删除 LDAP 用户。尝试对不存在的用户设置角色将导致错误。
内容选择器
nexus_content_selectors:
- name: docker-login
description: Docker 登录权限的选择器
search_expression: format=="docker" and path=~"/v2/"
有关内容选择器的更多信息,请参见 文档
要使用内容选择器,请添加带有 type: repository-content-selector
和适当的 contentSelector
的新权限。
- name: docker-login-privilege
type: repository-content-selector
contentSelector: docker-login
description: '登录到 Docker 注册表'
repository: '*'
actions:
- read
- browse
清理策略
nexus_repos_cleanup_policies:
# - name: mvn_cleanup
# format: maven2
# mode:
# notes: ""
# criteria:
# lastBlobUpdated: 60
# lastDownloaded: 120
# preRelease: RELEASES
# regexKey: "foo.*"
清理策略定义。可以与 repo 定义结合使用,选项 cleanup_policies
Blobstores 和库
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
# type: file
# path: /mnt/custom/path
# - name: s3-blobstore
# type: S3
# config:
# bucket: s3-blobstore
# accessKeyId: "{{ VAULT_ENCRYPTED_KEY_ID }}"
# secretAccessKey: "{{ VAULT_ENCRYPTED_ACCESS_KEY }}"
Blobstores 的创建。在初始创建后,blobstore 路径和库 blobstore 不能更新(此处的任何更新在重复配置时将被忽略)。
在 S3 上配置 blobstore 是为了方便,并非我们在 travis 上运行的自动测试的一部分。请注意,仅推荐在部署在 AWS 上的实例上存储在 S3 中。
nexus_repos_maven_proxy:
- name: central
remote_url: 'https://repo1.maven.org/maven2/'
layout_policy: permissive
# cleanup_policies:
# - mvn_cleanup
# maximum_component_age: -1
# maximum_metadata_age: 1440
# negative_cache_enabled: true
# negative_cache_ttl: 1440
- name: jboss
remote_url: 'https://repository.jboss.org/nexus/content/groups/public-jboss/'
# cleanup_policies:
# - mvn_cleanup
# maximum_component_age: -1
# maximum_metadata_age: 1440
# negative_cache_enabled: true
# negative_cache_ttl: 1440
# 示例带有登录/密码:
# - name: secret-remote-repo
# remote_url: 'https://company.com/repo/secure/private/go/away'
# remote_username: 'username'
# remote_password: 'secret'
# # maximum_component_age: -1
# # maximum_metadata_age: 1440
# # negative_cache_enabled: true
# # negative_cache_ttl: 1440
Maven 代理库 配置。
nexus_repos_maven_hosted:
- name: private-release
version_policy: release
write_policy: allow_once # "allow"、"allow_once" 或 "deny" 之一
# cleanup_policies:
# - mvn_cleanup
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"、"allow_once" 或 "deny" 之一
maximum_component_age: -1 # Nexus GUI 默认。仅适用于代理
maximum_metadata_age: 1440 # Nexus GUI 默认。仅适用于代理
negative_cache_enabled: true # Nexus GUI 默认。仅适用于代理
negative_cache_ttl: 1440 # Nexus GUI 默认。仅适用于代理
Docker、Pypi、Raw、Rubygems、Bower、NPM、Git-LFS 和 yum 库类型:
请参见 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
nexus_config_yum: false
这些默认均为 false,除非您通过 playbook、group_var 或 CLI 来重写它们,请注意您可能需要启用某些安全域,如果您希望使用 Maven 以外的其他库类型。这些默认为 false。
nexus_nuget_api_key_realm: false
nexus_npm_bearer_token_realm: false
nexus_docker_bearer_token_realm: false # 需要用于 docker 匿名访问
还可以通过启用远程用户域来启用。
nexus_rut_auth_realm: true
并通过定义
nexus_rut_auth_header: "CUSTOM_HEADER"
配置头部。
定时任务
这些是设置定时任务的快速示例和说明。有关可用任务类型和调度类型的详细信息,请参见 repo wiki 中的具体部分
nexus_scheduled_tasks: []
# # 清理 blobstore 的示例任务:
# - name: compact-docker-blobstore
# cron: '0 0 22 * * ?'
# typeId: blobstore.compact
# task_alert_email: [email protected] # 可选
# taskProperties:
# blobstoreName: {{ nexus_blob_names.docker.blob }} # 所有任务属性以字符串形式由 nexus 内部存储
# # 清除 maven 快照的示例任务
# - name: Purge-maven-snapshots
# cron: '0 50 23 * * ?'
# typeId: repository.maven.remove-snapshots
# task_alert_email: [email protected] # 可选
# taskProperties:
# repositoryName: "*" # * 表示所有库。如果只想要特定的库,请更改为库名称
# minimumRetained: "2"
# snapshotRetentionDays: "2"
# gracePeriodInDays: "2"
# booleanTaskProperties:
# removeIfReleased: true
# # 清除未使用的 docker 清单和映像的示例任务
# - name: Purge unused docker manifests and images
# cron: '0 55 23 * * ?'
# typeId: "repository.docker.gc"
# task_alert_email: [email protected] # 可选
# taskProperties:
# repositoryName: "*" # * 表示所有库。如果只想要特定的库,请更改为库名称
# # 清除不完整的 docker 上传的示例任务
# - name: Purge incomplete docker uploads
# cron: '0 0 0 * * ?'
# typeId: "repository.docker.upload-purge"
# task_alert_email: [email protected] # 可选
# taskProperties:
# age: "24"
要设置的 定时任务 。 typeId
和特定于任务的 taskProperties
/ booleanTaskProperties
可以这样猜测:
- 从
org.sonatype.nexus.scheduling.TaskDescriptorSupport
的 java 类型层次 - 通过在浏览器中检查任务创建 HTML 表单
- 通过查看浏览器 AJAX 请求,在手动配置任务时。
任务属性必须根据其类型在正确的 yaml 块中声明:
- 对于所有字符串属性(即库名称、blobstore 名称、时间段……):
taskProperties
。 - 对于所有布尔属性(即主要在 nexus 创建任务 GUI 中的复选框):
booleanTaskProperties
。
备份
nexus_backup_configure: false
nexus_backup_schedule_type: cron
nexus_backup_cron: '0 0 21 * * ?' # 请查看 nexus 创建任务 GUI 中的 cron 表达式定义
# nexus_backup_start_date_time: "yyyy-MM-dd'T'HH:mm:ss"
# nexus_backup_weekly_days: ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
# nexus_backup_monthly_days: {{ range(1,32) | list + [999] }}
nexus_backup_dir: '/var/nexus-backup'
nexus_backup_dir_create: true
nexus_restore_log: '{{ nexus_backup_dir }}/nexus-restore.log'
nexus_backup_rotate: false
nexus_backup_rotate_first: false
nexus_backup_keep_rotations: 4 # 默认保留 4 个备份轮换(当前 + 最近三个)
备份将在您将 nexus_backup_configure
设置为 true
后配置。
在这种情况下,将在 nexus 中配置一个脚本任务。
脚本任务的调度将默认为 cron
,并每天在 21:00 运行。您可以通过相应设置变量 nexus_backup_schedule_type
、nexus_backup_cron
、nexus_backup_start_date_time
、nexus_backup_weekly_days
和 nexus_backup_monthly_days
定义任意调度。有关其用法的更多信息,请查看 定时任务
参见 此任务的 Groovy 模板 获取详细信息。
此定时任务与您在 playbook 中声明的其他 nexus_scheduled_tasks
是独立的。
如果您希望进行备份到挂载目录(如 s3fs),可以将 nexus_backup_dir_create
设置为 false。
恢复程序
使用参数 -e nexus_restore_point=<YYYY-MM-dd-HH-mm-ss>
运行您的 playbook(例如 2017-12-17-21-00-00 表示 2017 年 12 月 17 日 21 时 0 分 0 秒)。
可能的限制
blobstore 副本是通过脚本定时任务直接由 nexus 制作的。此功能仅在相对较小的 blobstores(小于 50Go)上进行了测试,并且在生产前应谨慎使用并仔细测试更大的安装。在任何情况下,您可以自由在此角色之外实现自己的备份方案。
特殊维护/调试变量
这些在 defaults/main.yml
中不存在,旨在仅在命令行上用于维护/调试原因。
清空 nexus
警告:这将完全擦除当前数据。如果需要,请确保事先进行备份
如果您需要从头开始重启并重新安装一个空白的 nexus 实例,请使用 nexus_purge
变量。
ansible-playbook -i your/inventory.ini your_nexus_playbook.yml -e nexus_purge=true
强制注册 Groovy 脚本
这条安全,仅会使 playbook 运行时间更长(如果不需要)
出于性能考虑,我们通过多个 rsync 使用一些技巧来检测需要在 Nexus 中注册的维护 Groovy 脚本。在某些情况下(例如,错误的管理员密码、从先前的 nexus 实例恢复备份时未注册的脚本……),这可能导致在尝试运行所需的 Groovy 脚本时角色失败。
症状:当角色尝试运行以下示例中的脚本时,您会收到 HTTP 404 错误(使用 -v
选项运行 ansible playbook):
fatal: [nexus3-oss]: FAILED! => {"changed": false, "connection": "close", "content": "", "date": "Tue, 11 Sep 2018 07:57:44 GMT", "msg": "Status code was 404 and not [200, 204]: HTTP Error 404: Not Found", "redirected": false, "server": "Nexus/3.13.0-01 (OSS)", "status": 404, "url": "http://localhost:8081/service/rest/v1/script/update_admin_password/run", "x_content_type_options": "nosniff", "x_siesta_faultid": "914acef2-f644-4bd6-9a7d-ce19255ea3dd"}
在这种情况下,您可以使用 nexus_force_groovy_scripts_registration
变量强制(重新)注册 Groovy 脚本:
ansible-playbook -i your/inventory.ini your_playbook.yml -e nexus_force_groovy_scripts_registration=true
首次安装后更改管理员密码
nexus_default_admin_password: 'admin123'
此内容不应在您的 playbook 中更改。这个变量会在首次安装时填充 default nexus 管理员密码,并确保我们可以将管理员密码更改为 nexus_admin_password
。
如果您想在首次安装后更改管理员密码,可以临时将此值更改为您在命令行上的旧密码。在 playbook 中更改 nexus_admin_password
后,您可以运行:
ansible-playbook -i your/inventory.ini your_playbook.yml -e nexus_default_admin_password=oldPassword
升级 nexus 到最新版本
nexus_upgrade: true
如果固定了 nexus_version
,则此变量无效
除非您设置此变量,否则在针对已配置的主机运行时,角色将保留当前安装的 nexus 版本。传递此额外变量将触发自动检测最新版本并在可用时进行升级。
将该变量作为 playbook 的一部分设置会打破幂等性(也就是说,您的 playbook 将对系统进行更改,如果有新版本可用,尽管没有参数更改)。
我们强烈建议仅将此变量用作 ansible-playbook 调用的额外变量
ansible-playbook -i your/inventory.ini your_playbook.yml -e nexus_upgrade=true
修复因超时等待 nexus 端口而导致升级失败
如果您有一个大型 nexus 库,您可能偶尔会看到升级时出现错误消息
RUNNING HANDLER [nexus3-oss : wait-for-nexus-port] *************
fatal: [nexushost]: FAILED! => {"changed": false, "elapsed": 300, "msg": "Timeout when waiting for 127.0.0.1:8081"}
这很可能是因为 nexus 升级过程(即迁移内部 orientdb)所需的时间超过了默认的 300 秒。您可以通过在秒数中设置自定义超时和/或重试次数来克服这种情况 对于处理程序任务。
ansible-playbook -i your/inventory.ini your_playbook.yml \
-e nexus_upgrade=true \
-e nexus_wait_for_port_timeout=600 \
-e nexus_wait_for_port_retries=2
跳过配置任务
nexus_run_provisionning: false
默认情况下该变量未设置,默认为 true
。将其设置为 false
将导致角色跳过所有配置任务,因此 不创建/更新:
- LDAP 配置
- 内容选择器
- 权限
- 角色
- 用户(除了检查/更新管理员密码)
- blobstores
- 库
- 任务(如果启用,备份仍将配置)
该设置可以节省时间,如果您有大量配置的库/用户/角色……并且想要运行角色只为检查 nexus 是否正确安装,或恢复备份,或升级 nexus 版本。
我们强烈建议仅将此变量用作 ansible-playbook 调用的额外变量
ansible-playbook -i your/inventory.ini your_playbook.yml -e nexus_run_provisionning=false
强制递归检查 blobstores 目录的所有权
在版本 2.4.9 中引入
nexus_blobstores_recurse_owner: true
在 2.4.9 之前,创建 blobstores 目录的任务会递归检查所有文件的所有权。创建时(目录为空)或对于小型 blobstores 不会造成问题,但对于拥有大量文件的较大 blobstores 可能会导致长时间延迟。
默认情况下,已关闭对所有权的递归检查,以防止额外的延迟。如果由于某种原因您需要确保 blobstore 目录中的所有文件均由 nexus 用户拥有,则可以强制检查:
ansible-playbook -i your/inventory.ini your_playbook.yml -e nexus_blobstores_recurse_owner=true
依赖关系
Java 和 httpd 的要求可以满足以下 galaxy 角色:
请随意使用它们或根据您的需要实现自己的安装方案。
示例 Playbook
---
- name: Nexus
hosts: nexus
become: yes
vars:
nexus_timezone: 'Canada/Eastern'
nexus_admin_password: "{{ vault_nexus_admin_password }}"
nexus_public_hostname: '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: 'Company 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: geerlingguy.java, vars: 查看角色文档以了解您的分发/版本 }
# 仅 Debian/Ubuntu
# - { role: geerlingguy.apache, apache_create_vhosts: no, apache_mods_enabled: ["proxy.load", "proxy_http.load", "headers.load"], apache_remove_default_vhost: true, tags: ["geerlingguy.apache"] }
# 仅 RedHat/CentOS
- { role: geerlingguy.apache, apache_create_vhosts: no, apache_remove_default_vhost: true, tags: ["geerlingguy.apache"] }
- { role: ansible-thoteam.nexus3-oss, tags: ['ansible-thoteam.nexus3-oss'] }
开发、贡献和测试
贡献
欢迎对该角色的所有贡献,无论是修复 bug、添加新功能还是文档。
如果您希望贡献:
- 通过 github 界面在您的名字/组织下分叉存储库
- 在您自己的存储库中创建具有意义名称的分支。我们建议以下命名约定:
feat/<someFeature>
用于特性fix/<someBugFix>
用于修复 bugdocfix/<someDocFix>
用于仅文档修复
- 如果要启动重要的功能更改,请及早打开拉取请求,描述您想要做的事情,以便我们在必要时可以讨论。这将防止您在不能最终合并的更改上做大量的辛苦工作。
- 如果您在拉取请求中遇到构建错误,请查看 travis 日志并修复相关错误。
此外,如果您有时间进行代码审查、合并发布等,请发送电子邮件至 contact@thoteam.com 与我们联系。
测试
该角色包括通过 travis 的测试和 CI 集成。目前,我们测试:
- Groovy 语法
- yaml 语法和编码标准(yamllint)
- ansible 最佳实践(ansible lint)
- 在 3 个不同 Linux 平台上的一组基本部署
- Centos 8
- Debian Buster
- Ubuntu Bionic(18.04)
其他测试适用于旧版本平台,但由于性能原因未在 CI 中运行:
- Centos 7
- Debian Stretch
- Ubuntu Xenial(16.04)
Groovy 语法
此角色包含一组用于配置 nexus 的 Groovy 文件。
如果向 Groovy 文件提交更改,请在推送更改之前先在本地运行 Groovy 语法检查
./tests/test_groovySyntax.sh
这将确保您推送具有正确语法的 Groovy 文件,减少 travis 上的检查错误数量。
您需要在本地安装 groovy 软件包以运行此测试。
Molecule 默认场景
该角色在 travis 中使用 molecule 进行测试。您可以在本地运行这些测试。实现此操作的最佳方法是通过 Python 虚拟环境。有关详细信息,请查看 requirements.txt。
# 注意: 以下路径应位于工作目录之外
virtualenv /path/to/some/pyenv
. /path/to/some/pyenv/bin/activate
pip install -r requirements.txt
molecule [create|converge|destroy|test] -s <scenario name>
deactivate
请查看 molecule 文档(一个好的起点是 molecule --help
)了解进一步用法。
当前提出的场景指的是经过测试的平台(见 molecule/
目录)。如果您启动场景并让容器运行(即使用 converge
进行简单部署),您可以通过浏览器访问运行实例,地址为 https://localhost:molecule/<scenario>/molecule.yml
文件。出于方便,以下是场景与配置端口的对应关系:
- default-centos7 => https://localhost:8090
- default-centos8 => https://localhost:8095
- default-debian_buster => https://localhost:8091
- default-debian_stretch => https://localhost:8092
- default-ubuntu_16.04 => https://localhost:8093
- default-ubuntu_18.04 => https://localhost:8094
为了加快测试速度,molecule 使用具有自动构建的 docker hub 映像。
- Git 存储库: https://github.com/docker-ThoTeam/molecule_apache_openjdk8
- Docker hub 注册: https://hub.docker.com/repository/docker/thoteam/molecule_apache_openjdk8
Molecule selinux 场景
警告: 由于与 molecule 3.0 的兼容性原因,此场景暂时被移除。我们等待决定是否可以重新引入该功能
我们包含了第二个 molecule selinux
场景。该场景未在 travis 中运行,但可以在本地使用,以便:
- 测试 selinux 集成(在 centos 上)。
- 运行测试并在您的本地机器上访问正在运行的 VMs。
如果您希望使用此场景,您需要
- VirtualBox
- Vagrant
- molecule
典型的工作流程如下:
molecule create -s selinux
。一旦此操作完成,您将看到在 VirtualBox 控制台中有两个 Vagrant VMs(centos7 和 debian-stretch)。 这些 Vagrant 框是从 http://vagrant.thoteam.com 提取的。molecule converge -s selinux
将运行 场景测试 playbook 针对两个 VMs。 您可以在命令行中传递额外变量以覆盖 playbook 或默认变量(例如,molecule converge -s selinux -- -e nexus_backup_rotate=true
)。您可以随时多次聚合。- 现在您可以通过 https://localhost:9101(centos7)或 https://localhost:9102(debian-stretch)访问 GUI。 您需要为自签名的 SSL 证书添加安全例外。如果您没有使用上面命令行变量更改的值,默认角色管理员密码为 "changeme"。
- 当您对测试满意时,可以使用
molecule destroy -s selinux
回收使用的空间。
许可证
GNU GPLv3