tasks/main.yml
- name: Install Ubuntu packages
when: ansible_distribution == 'Ubuntu'
ansible.builtin.include_tasks:
file: install_ubuntu.yml
- name: Install Rocky packages
when: ansible_distribution == 'Rocky'
ansible.builtin.include_tasks:
file: install_rocky.yml
- name: Copy update status script
ansible.builtin.copy:
src: files/{{ ansible_os_family|lower }}_update_status.py
dest: /usr/local/bin/update_status
owner: root
group: root
mode: '0755'
- name: Copy reboot status script
ansible.builtin.copy:
src: files/{{ ansible_os_family|lower }}_reboot_status.py
dest: /usr/local/bin/reboot_status
owner: root
group: root
mode: '0755'
#- name: Get snmp community string from Azure key vault
# local_action:
# module: azure.azcollection.azure_rm_keyvaultsecret_info
# vault_uri: "{{ az_keyvault_url }}"
# register: snmp_community
#- name: Print snmp community string
# debug:
# msg: "SNMP Community: {{ snmp_community }}"
- name: Configure snmpd
ansible.builtin.template:
src: templates/snmpd.conf.j2
dest: /etc/snmp/snmpd.conf
owner: root
group: root
mode: 0600
backup: yes
notify: Restart snmpd
- name: Create a cron to output package update status once an hour
ansible.builtin.cron:
name: check update status
job: "/usr/local/bin/update_status /tmp/update_status.txt > /dev/null 2>&1"
minute: "0"
state: present
user: root
cron_file: ansible_update_status
- name: Create a cron to output reboot status once an hour
ansible.builtin.cron:
name: "check reboot status"
job: "/usr/local/bin/reboot_status /tmp/reboot_status.txt > /dev/null 2>&1"
minute: "5"
state: present
user: root
cron_file: ansible_reboot_status
- name: Create cron to output reboot status after a restart
ansible.builtin.cron:
name: "update reboot status after a reboot"
job: "/usr/local/bin/reboot_status /tmp/reboot_status.txt > /dev/null 2>&1"
special_time: reboot
state: present
user: root
cron_file: ansible_reboot_status
- name: Run update_status
ansible.builtin.command: "/usr/local/bin/update_status /tmp/update_status.txt"
- name: Run upgrade_status
ansible.builtin.command: "/usr/local/bin/reboot_status /tmp/reboot_status.txt"
tasks/install_ubuntu.yml
- name: Install SNMP packages
ansible.builtin.apt:
pkg: "{{ snmp_packages[ansible_distribution|lower] }}"
state: latest
update_cache: true
Export Route53 Zone
#!/bin/bash
zonename=$1
hostedzoneid=$(aws route53 list-hosted-zones --output json | jq -r ".HostedZones[] | select(.Name == \"$zonename.\") | .Id" | cut -d'/' -f3)
aws route53 list-resource-record-sets --hosted-zone-id $hostedzoneid --output json | jq -jr '.ResourceRecordSets[] | "\(.Name) \t\(.TTL) \t\(.Type) \t\(.ResourceRecords[]?.Value)\n"'
Create a Jira issue with curl
curl --request POST \
--url 'https://opennms.atlassian.net/rest/api/3/issue' \
--user 'prefix@domain.com:1234567890ABCDEF12345678' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"fields": {
"summary": "Test issue for cloud API",
"issuetype": {
"name": "Task"
},
"project": {
"key": "GANIMAN"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "This is a test issue.",
"type": "text"
}
]
}
]
}
}
}'
Create an OpenNMS XML Requisition from Azure VMs
#!/bin/bash
APPLICATIONID="Application (client) ID"
APPLICATIONSECRET="Application Secret"
TENANTID="Directory (tenant) ID"
if ! command -v az >/dev/null 2>&1 ; then
echo "az command not found, please install az"
exit 0
fi
if ! command -v xmllint >/dev/null 2>&1 ; then
echo "xmllint command not found, please install xmllint"
exit 0
fi
if ! command -v jq >/dev/null 2>&1 ; then
echo "jq not found, please install jq"
exit 0
fi
az login --service-principal -u "${APPLICATIONID}" -p "${APPLICATIONSECRET}" --tenant "${TENANTID}" --output none
DATE="$(date --utc +%FT%TZ)"
XML="<model-import xmlns=\"http://xmlns.opennms.org/xsd/config/model-import\" date-stamp=\"${DATE}\" foreign-source=\"Azure\" last-import=\"${DATE}\">"
for RESOURCEGROUP in $(az group list --query [].name --output tsv)
do
for NODE in $(az vm list --resource-group "${RESOURCEGROUP}" --query "[].{NodeLabel:name, Tags:tags, OS:storageProfile.osDisk.osType, VM:vmId}" --output json | jq -c '.[]'); do
_jq()
{
echo ${NODE} | jq -r ${1}
}
NODELABEL=$(_jq '.NodeLabel')
OS=$(_jq '.OS')
ENVIRONMENT=$(_jq '.Tags.Environment')
VMID=$(_jq '.VM')
if [ "$ENVIRONMENT" = "Production" ]; then
LOCATION=$(_jq '.NodeLabel')
PUBIP=$(az vm list-ip-addresses --resource-group "${RESOURCEGROUP}" --name "${NODELABEL}" --query "[].virtualMachine.network.publicIpAddresses[0].ipAddress" --output tsv)
# TODO: GeoIP lookup of IP address to populate city, state, zip, country, latitue, longitude
XML=$XML"
<node building=\"${RESOURCEGROUP}\" foreign-id=\"${VMID}\" node-label=\"${NODELABEL}\">
<interface ip-addr=\"$PUBIP\" status=\"1\" snmp-primary=\"P\">
<!-- <monitored-service service-name=\"HTTP\"/> -->
</interface>
<category name=\"Azure\"/>
<category name=\"${LOCATION}\"/>
<category name=\"${RESOURCEGROUP}\"/>
<category name=\"${ENVIRONMENT}\"/>
<category name=\"${OS}\"/>
<asset name=\"city\" value=\"\"/>
<asset name=\"state\" value=\"\"/>
<asset name=\"zip\" value=\"\"/>
<asset name=\"country\" value=\"\"/>
<asset name=\"latitude\" value=\"\"/>
<asset name=\"longitude\" value=\"\"/>
</node>
"
fi
done
done
XML=$XML"</model-import>"
echo "$XML" | xmllint --format -