Skip to content

Instantly share code, notes, and snippets.

@mrlesmithjr
Created August 11, 2020 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrlesmithjr/4de024690227fddfa9c0d8d3b9eae2f6 to your computer and use it in GitHub Desktop.
Save mrlesmithjr/4de024690227fddfa9c0d8d3b9eae2f6 to your computer and use it in GitHub Desktop.
---
# Global provisioners will run against every node in the order specified.
# These provisioners run after all node specific provisioners if defined.
#
# For node specific provisioners add at the node level
provisioners: []
# - type: shell
# inline: |
# if [ -f /etc/os-release ]; then
# os_name="$(awk -F= '/^NAME/{ print $2 }' /etc/os-release | sed 's/"//g')"
# os_version_id="$(awk -F= '/^VERSION_ID/{ print $2}' /etc/os-release | sed 's/"//g')"
# echo $os_name
# echo $os_version_id
# fi
# privileged: true
# - type: shell
# path:
# - scripts/test.sh
# privileged: false
# - type: ansible_local
# playbooks:
# - /vagrant/playbooks/test.yml
# - type: ansible
# playbooks:
# - playbooks/test.yml
# Synced folders
# Additional synced folders.
# By default scripts and playbooks are synced, and available in each node as:
# /playbooks, /scripts, /vagrant/playbooks, and /vagrant/scripts. They are
# duplicated because of the symlinks within /vagrant. This is as designed.
synced_folders:
[]
# - type: nfs
# src: example1/
# mountpoint: /example1
# - type: rsync
# src: example2/
# mountpoint: /example2
# Define nodes which are required for the environment you intend on creating.
nodes:
- name: repo01
ansible_groups:
- repo
box: mrlesmithjr/bionic64
desktop: false
disks: []
interfaces:
- ip: 192.168.250.11
auto_config: true
method: static
linked_clone: true
mem: 2048
provision: true
# Node specific provisioners
provisioners: []
vcpu: 2
port_forwards: []
windows: false
- name: bionic
ansible_groups:
- repo_clients
box: mrlesmithjr/bionic64
desktop: false
disks: []
interfaces:
- ip: 192.168.250.12
auto_config: true
method: static
linked_clone: true
mem: 512
provision: true
# Node specific provisioners
provisioners: []
vcpu: 1
port_forwards: []
windows: false
- name: centos
ansible_groups:
- repo_clients
box: mrlesmithjr/centos7
desktop: false
disks: []
interfaces:
- ip: 192.168.250.13
auto_config: true
method: static
linked_clone: true
mem: 512
provision: true
# Node specific provisioners
provisioners: []
vcpu: 1
port_forwards: []
windows: false
- name: focal
ansible_groups:
- repo_clients
box: mrlesmithjr/focal64
desktop: false
disks: []
interfaces:
- ip: 192.168.250.14
auto_config: true
method: static
linked_clone: true
mem: 512
provision: true
# Node specific provisioners
provisioners: []
vcpu: 1
port_forwards: []
windows: false
- name: windows
ansible_groups:
- repo_clients
box: mrlesmithjr/windows2019
desktop: false
disks: []
interfaces:
- ip: 192.168.250.15
auto_config: true
method: static
linked_clone: true
mem: 1536
provision: true
# Node specific provisioners
provisioners: []
vcpu: 1
port_forwards: []
windows: true
@mrlesmithjr
Copy link
Author

playbook.yml:

---
- hosts: repo
  vars:
    pri_domain_name: test.vagrant.local
  tasks:
    - import_role:
        name: ansible-nexus-repo-oss

- hosts: repo_clients
  vars:
    repo_url: "http://{{ repo_host }}:{{ repo_port }}"
    repo_host: 192.168.250.11
    repo_port: 8081
  handlers:
    - name: apt-update
      apt:
        update_cache: true
      become: true

    - name: yum-clean
      command: yum clean all
      become: true
      args:
        warn: false
  tasks:
    - name: Get Repos
      find:
        paths: /etc/yum.repos.d
        patterns: "*.repo"
      register: yum_repos
      when: ansible_os_family == "RedHat"

    - name: Remove Repos
      file:
        path: "{{ item.path }}"
        state: absent
      become: true
      loop: "{{ yum_repos.files }}"
      when:
        - ansible_os_family == "RedHat"
        - item.path != "/etc/yum.repos.d/nexus.repo"

    - name: Install EPEL Repo
      yum:
        name: epel-release
        state: present
      become: true
      when: ansible_os_family == "RedHat"

    - name: Add Nexus YUM Repo
      copy:
        content: |
          [base]
          name=CentOS-$releasever - Base
          baseurl={{ repo_url }}/repository/centos/$releasever/os/$basearch/

          [updates]
          name=CentOS-$releasever - Updates
          baseurl={{ repo_url }}/repository/centos/$releasever/updates/$basearch/

          [extras]
          name=CentOS-$releasever - Extras
          baseurl={{ repo_url }}/repository/centos/$releasever/extras/$basearch/

          [epel]
          name=Extra Packages for Enterprise Linux 7 - $basearch
          #baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
          metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
          failovermethod=priority
          enabled=1
          gpgcheck=1
          gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
        dest: /etc/yum.repos.d/nexus.repo
      become: true
      when: ansible_os_family == "RedHat"
      notify:
        - yum-clean

    - name: Remove APT Sources
      file:
        path: /etc/apt/sources.list
        state: absent
      become: true
      when: ansible_os_family == "Debian"

    - name: Adding APT Sources
      copy:
        content: |
          deb {{ repo_url }}/repository/{{ ansible_distribution_release|lower }}/ {{ ansible_distribution_release|lower }} main restricted
          deb {{ repo_url }}/repository/{{ ansible_distribution_release|lower }}/ {{ ansible_distribution_release|lower }}-updates main restricted
          deb {{ repo_url }}/repository/{{ ansible_distribution_release|lower }}/ {{ ansible_distribution_release|lower }} universe
          deb {{ repo_url }}/repository/{{ ansible_distribution_release|lower }}/ {{ ansible_distribution_release|lower }}-updates universe
          deb {{ repo_url }}/repository/{{ ansible_distribution_release|lower }}/ {{ ansible_distribution_release|lower }} multiverse
          deb {{ repo_url }}/repository/{{ ansible_distribution_release|lower }}/ {{ ansible_distribution_release|lower }}-updates multiverse
          deb {{ repo_url }}/repository/{{ ansible_distribution_release|lower }}/ {{ ansible_distribution_release|lower }}-backports main restricted universe multiverse
        dest: /etc/apt/sources.list.d/nexus.list
      become: true
      notify:
        - apt-update
      when: ansible_os_family == "Debian"

    - name: Wait for {{ repo_url }}
      wait_for:
        host: "{{ repo_host }}"
        port: "{{ repo_port }}"
      when: ansible_os_family != "Windows"

    - name: Flush Handlers
      meta: flush_handlers

    - name: Update YUM
      yum:
        update_cache: true
      become: true
      when: ansible_os_family == "RedHat"

    - name: Install Packages
      apt:
        name:
          - curl
          - redis-server
          - mariadb-server
          - nginx
        state: present
      become: true
      when: ansible_os_family == "Debian"

    - name: Install Packages
      yum:
        name:
          - curl
          - redis
          - mariadb-server
          - nginx
        state: present
      become: true
      when: ansible_os_family == "RedHat"

    # - name: Configure Chocolatey
    #   win_chocolatey_config:
    #     name: proxy
    #     value: "{{ repo_url }}/repository/chocolatey-proxy/"
    #     state: absent
    #   when: ansible_os_family == "Windows"

    - name: Install Packages
      win_chocolatey:
        name:
          - git
          # - putty
          # - chrome
        proxy_url: "{{ repo_url }}/repository/chocolatey-proxy/"
        state: present
      register: result
      until: result is successful
      retries: 5
      when: ansible_os_family == "Windows"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment