Skip to content

Commit

Permalink
Merge branch 'main' into patty
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonking3 committed Mar 29, 2024
2 parents c8e563e + 2ac0b98 commit 38a308a
Show file tree
Hide file tree
Showing 21 changed files with 348 additions and 38 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: Release
on:
release:
types:
- created
workflow_dispatch:
inputs:
tag:
description: 'Image Tag'
required: true
type: string
default: 'latest'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/mdd


jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
if: ${{ ! inputs.tag }}
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push Docker image
if: ${{ inputs.tag }}
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.tag }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ ansible_collections/
.cache/
collections/
envvars
*.gz
*.gz
.vscode/
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM --platform=linux/amd64 ubuntu:22.04

ARG build_date=unspecified

# workspace location
ARG WORKSPACE
ENV WORKSPACE ${WORKSPACE:-/ansible}
ENV ANSIBLE_COLLECTIONS_PATH /

COPY requirements.txt /tmp/requirements.txt
COPY requirements.yml /tmp/requirements.yml
COPY . /tmp/ansible-mdd

USER root
RUN mkdir /root/.ssh && bash -c 'echo -e "Host *\n KexAlgorithms +diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1" > /root/.ssh/config'
RUN mkdir /ansible_collections && chmod 777 /ansible_collections
RUN apt-get update && \
apt-get install -y python3.10 python3-pip sshpass git && \
pip3 install --upgrade --no-cache-dir setuptools pip && \
echo "===> Installing PIP Requirements <===" && \
pip3 install --no-cache -r /tmp/requirements.txt && \
echo "===> Installing Ansible Collections <===" && \
rm -rf /var/lib/apt/lists/* && \
ansible-galaxy collection install -r /tmp/requirements.yml

ENV ANSIBLE_HOST_KEY_CHECKING=false \
ANSIBLE_RETRY_FILES_ENABLED=false \
ANSIBLE_SSH_PIPELINING=true

WORKDIR ${WORKSPACE}
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ publish: $(TARBALL_NAME) ## Publish Collection (set env:GALAXY_TOKEN)
format: ## Format Python code
yapf --style=yapf.ini -i -r *.py $(PYDIRS)

test: $(VENV) $(TARBALL_NAME) ## Run Sanity Tests
test: clean build $(VENV) $(TARBALL_NAME) ## Run Sanity Tests
$(RM) -r ./ansible_collections
ansible-galaxy collection install --force $(TARBALL_NAME) -p ./ansible_collections
cd ./ansible_collections/ciscops/mdd && git init .
Expand All @@ -45,7 +45,9 @@ test: $(VENV) $(TARBALL_NAME) ## Run Sanity Tests
$(VENV_BIN)/pip uninstall -y ansible-base
$(VENV_BIN)/pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check
cd ./ansible_collections/ciscops/mdd && ../../../$(VENV_BIN)/ansible-test sanity --docker -v --color
$(RM) $(TARBALL_NAME)
$(RM) -r ./ansible_collections
$(RM) -r ./venv

clean: ## Clean
$(RM) $(TARBALL_NAME)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cisco Model Driven Devops Ansible Collection
# Cisco Model-Driven Devops Ansible Collection

This Ansible Collection is an implementation of Model-Driven DevOps and includes the following roles:
* [oc](https://github.com/model-driven-devops/ansible-mdd/blob/main/roles/oc/README.md)
Expand All @@ -8,14 +8,14 @@ This Ansible Collection is an implementation of Model-Driven DevOps and includes
* [netbox](https://github.com/model-driven-devops/ansible-mdd/blob/main/roles/netbox/README.md)
* [nso](https://github.com/model-driven-devops/ansible-mdd/blob/main/roles/nso/README.md)

## Dependancies
### Environmnet Variables
## Dependencies
### Environment Variables
If using NetBox:
- `NETBOX_API`
- `NETBOX_TOKEN`

To use an external NSO (ie. not deployed in CML):
- `NSO_URL` Protocol, FQDN or IP address and port (ex. `http://192.168.1.100:8080`)
To use an external NSO (i.e. not deployed in CML):
- `NSO_URL` Protocol, FQDN or IP address and port (e.g. `http://192.168.1.100:8080`)
- `NSO_USERNAME`
- `NSO_PASSWORD`

Expand Down
7 changes: 5 additions & 2 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace: ciscops
name: mdd

# The version of the collection. Must be compatible with semantic versioning
version: 1.2.7
version: 1.2.14

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down Expand Up @@ -72,4 +72,7 @@ build_ignore:
- '.env'
- '.github'
- 'tests/output/'
- 'ansible_collections/'
- 'ansible_collections'
- 'Dockerfile'
- 'requirements.txt'
- 'requirements.yml'
4 changes: 2 additions & 2 deletions playbooks/cml_update_lab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@

- name: Create topology file
copy:
content: "{{ topology | to_nice_yaml(indent=2,sort_keys=False) }}"
content: "{{ topology | ciscops.mdd.to_even_nicer_yaml }}"
dest: "{{ lookup('env', 'PWD') }}/files/cml_lab.yaml"
run_once: yes
no_log: yes

- name: Create mapping file
copy:
content: "{{ {'all': {'hosts': results.mappings}} | to_nice_yaml(indent=2,sort_keys=False) }}"
content: "{{ {'all': {'hosts': results.mappings}} | ciscops.mdd.to_even_nicer_yaml }}"
dest: "{{ lookup('env', 'PWD') }}/{{ inventory_dir }}/cml_intf_map.yml"
run_once: yes
2 changes: 1 addition & 1 deletion playbooks/nso_dump_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
nso_device_config: "{ 'mdd_data': { 'config': {{ nso_device_config['config'] }} } }"

- copy:
content: "{{ nso_device_config | to_nice_yaml(indent=2,sort_keys=False) }}"
content: "{{ nso_device_config | ciscops.mdd.to_even_nicer_yaml }}"
dest: "{{ current_dir }}/device_config_data/{{ inventory_hostname }}.yml"
10 changes: 5 additions & 5 deletions playbooks/nso_update_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
when: ('oc' in mdd_data_types)
throttle: "{{ workers }}"
block:
- name: Translate and truncate interface names
- name: Translate/truncate interface names and truncate config
set_fact:
mdd_data: "{{ mdd_data | ciscops.mdd.intf_xform(cml_intf_xlate) }}"
when: (cml_group is defined and cml_group in group_names) and (cml_intf_xlate is defined and cml_intf_xlate)
mdd_data: "{{ mdd_data | ciscops.mdd.config_xform(cml_intf_xlate | default(None), cml_truncate_list | default(None), cml_vlan_list | default(None)) }}"
when: (cml_intf_xlate is defined and cml_intf_xlate) or (cml_truncate_list is defined and cml_truncate_list) or (cml_vlan_list is defined and cml_vlan_list)

- name: Update MDD Data
ansible.builtin.include_role:
Expand Down Expand Up @@ -57,14 +57,14 @@
tasks_from: update_rollback_list
when: rollback_id is defined and rollback_id and netbox_available | default(false)

- name: Run update_report
- name: Run update report
hosts: network
connection: local
gather_facts: no
vars:
dry_run: true
tasks:
- name: Update OC Data
- name: Generate report
include_role:
name: ciscops.mdd.nso
tasks_from: update_report
Expand Down
8 changes: 4 additions & 4 deletions playbooks/show.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
roles:
- ciscops.mdd.data
tasks:
- name: Translate and truncate interface names
- name: Translate/truncate interface names and truncate config
set_fact:
mdd_data: "{{ mdd_data | ciscops.mdd.intf_xform(cml_intf_xlate) }}"
when: (cml_group is defined and cml_group in group_names) and (cml_intf_xlate is defined and cml_intf_xlate)
mdd_data: "{{ mdd_data | ciscops.mdd.config_xform(cml_intf_xlate | default(None), cml_truncate_list | default(None), cml_vlan_list | default(None)) }}"
when: (cml_intf_xlate is defined and cml_intf_xlate) or (cml_truncate_list is defined and cml_truncate_list) or (cml_vlan_list is defined and cml_vlan_list)

- debug:
var: mdd_data
Loading

0 comments on commit 38a308a

Please sign in to comment.