Skip to content

Instantly share code, notes, and snippets.

@cecil
Last active October 19, 2017 02:26
Show Gist options
  • Select an option

  • Save cecil/def201d8930e6a5f526a to your computer and use it in GitHub Desktop.

Select an option

Save cecil/def201d8930e6a5f526a to your computer and use it in GitHub Desktop.
ansible playbook - ipmi dnsmasq /etc/ethers generator and ipmitool configurator
---
# set up ipmi password and dhcp configuration, use in conjuction with ipmiyuck-pullinfo.yaml
# Display/configure lan settings
# ipmitool lan set 1 ipsrc dhcp
# ipmitool lan print 1
#
- hosts: all:!hou-dc-head
vars_prompt:
- name: "ipmi_pass"
prompt: "Enter IPMI password"
private: yes
tasks:
- name: install screen
yum: name={{item}} state=installed
with_items:
- screen
- telnet
- ipmitool
# service restart output is shitty
- service: >
name=ipmi
state=restarted
enabled=yes
ignore_errors: yes
- name: configure IPMI interface dhcp
shell: ipmitool lan set 1 ipsrc dhcp
- pause: seconds=10
- name: get ipmi IP address
shell: ipmitool lan print 1 | egrep ^IP\ Address\ \ | awk '{print $4}'
register: ipmi_address
- name: confirm ip address
debug: msg="host ip {{ ansible_default_ipv4.address }} ipmi ip {{ ipmi_address.stdout }}"
- name: set IPMI password
shell: ipmitool user set password 2 {{ ipmi_pass }}
---
#
# quick hack
#
# this playbook will check ipmitool for the ipmi mac address
# and create a line formatted for dnsmasq's /etc/ethers file
# ipmi address will be in the ipmi subnet, but last octet
# will mirror the primary network interface on the host
#
# see DNSMASQ(8) for additional information on dnsmasq
#
# example :
# host A's primary IP is 10.10.10.99 on eth0
# the ipmi mac address is 34:17:eb:e5:00:1B
# the ipmi subnet is 10.11.12.0/24
#
# ipmimac-etc-ethers is populated with :
# 34:17:eb:e5:00:1B 10.11.12.99
#
# This script gathers additional info for CMDB cross referencing as well
- hosts: all
vars:
ipmi_prefix: 10.11.12.
tasks:
- name: get ipmi mac address
shell: ipmitool lan print 1 | egrep ^MAC | awk '{print $4}'
register: ipmi_mac
- name: ipmimac /etc/ethers file
local_action: >
lineinfile
dest=./files/ipmimac-etc-ethers
regexp="^{{ ipmi_mac.stdout }} {{ ansible_default_ipv4.address }}"
line="{{ ipmi_mac.stdout }} {{ ipmi_prefix }}{{ ansible_default_ipv4.address.split('.')[3] }}"
- name: mac2host file
local_action: lineinfile dest=./files/ipmimac-mac-hostname
regexp='^{{ ipmi_mac.stdout }}'
line='{{ ipmi_mac.stdout }} {{ ansible_default_ipv4.macaddress }} {{ ansible_fqdn }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment