Created
June 29, 2018 07:59
-
-
Save gustavomcarmo/af9a38b31b7caea98fb8e6fd1d04496b to your computer and use it in GitHub Desktop.
Ansible playbook to setup a Maven environment for a user in a remote host. The user then will use a instance of Nexus for downloading Java artifacts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: nexus-client-hosts | |
gather_facts: no | |
vars_prompt: | |
- name: "maven_master_password" | |
prompt: "Maven master password" | |
private: yes | |
- name: "nexus_username" | |
prompt: "Nexus username" | |
private: no | |
- name: "nexus_password" | |
prompt: "Nexus password" | |
private: yes | |
- name: "nexus_maven_public_url" | |
prompt: "Nexus maven-public repo URL" | |
private: no | |
tasks: | |
- name: Encrypt Maven master password | |
shell: mvn --encrypt-master-password "{{maven_master_password}}" | |
register: encryption_result | |
- name: Store de encrypted password in the ~/.m2/settings-security.xml | |
template: | |
src: settings-security.xml | |
dest: ~/.m2/settings-security.xml | |
vars: | |
- encrypted_maven_master_password: "{{encryption_result.stdout}}" | |
- name: Encrypt Nexus password | |
shell: mvn --encrypt-password "{{nexus_password}}" | |
register: encryption_result | |
- name: Store de encrypted password in the ~/.m2/settings.xml | |
template: | |
src: settings.xml | |
dest: ~/.m2/settings.xml | |
vars: | |
- encrypted_nexus_password: "{{encryption_result.stdout}}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<settingsSecurity> | |
<master>{{encrypted_maven_master_password}}</master> | |
</settingsSecurity> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> | |
<servers> | |
<server> | |
<id>nexus</id> | |
<username>{{nexus_username}}</username> | |
<password>{{encrypted_nexus_password}}</password> | |
</server> | |
</servers> | |
<mirrors> | |
<mirror> | |
<!--This sends everything else to /public --> | |
<id>nexus</id> | |
<mirrorOf>*</mirrorOf> | |
<url>{{nexus_maven_public_url}}</url> | |
</mirror> | |
</mirrors> | |
<profiles> | |
<profile> | |
<id>nexus</id> | |
<!--Enable snapshots for the built in central repo to direct --> | |
<!--all requests to nexus via the mirror --> | |
<repositories> | |
<repository> | |
<id>central</id> | |
<url>http://central</url> | |
<releases><enabled>true</enabled></releases> | |
<snapshots><enabled>true</enabled></snapshots> | |
</repository> | |
</repositories> | |
<pluginRepositories> | |
<pluginRepository> | |
<id>central</id> | |
<url>http://central</url> | |
<releases><enabled>true</enabled></releases> | |
<snapshots><enabled>true</enabled></snapshots> | |
</pluginRepository> | |
</pluginRepositories> | |
</profile> | |
</profiles> | |
<activeProfiles> | |
<!--make the profile active all the time --> | |
<activeProfile>nexus</activeProfile> | |
</activeProfiles> | |
</settings> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment