/ansible-ippower9258

Ansible scripts to get and set the state of the power outlets on the Opengear/Aviosys IP Power 9258 PDU

ansible-ippower9258

Ansible scripts to get and set the state of the power outlets on the Opengear/Aviosys IP Power 9258 PDU

why

I want to automate powering up and shutting down my servers. I use this in combination with ipmiutils to gracefully shut down my servers, and then disconnect power from them. To power up, the servers are set in the BIOS to start when power is applied, so I only need to remotely turn on the power to boot a server.

Generally speaking, I don't need to use my servers when I am away from home. I'm creating an automation script that detects when I'm leaving or sleepting and powers down the house. This project was born from necessity.

benefit

Cutting power to the servers reduces the overall load on the electrical circuit, saving money. Automatically shutting down an unused server will save a lot of money over time. It's always about the money, isn't it?

how to use

The IP Power 9258 is great except for managing the outlets using the device controls. When you want to change an Outlet to/from Off or On, it will blink all the outlets, cutting them off and on until you swith to the correct outlet to control its state. All of your servers will cut off and on, off and on. This is a great way to destroy your data.

However, the web console is great and easy to use. One problem is making a configuration change will reboot the unit, and cutting power to everything connected briefly. So be advised to test these scripts with no server/device plugged into the unit, in case you need to make configuration changes on the 9258 device.

To use, curl or visit this url to test if this will work on your IP Power. The default user is admin, and the default passsowrd is '12345678'. Change it if needed, and change the IP address as needed. We will use 192.168.0.5 in this example:

curl 'http://admin:12345678@192.168.0.5/Set.cmd?CMD=GetPower'

If you get something like this back 'p61=1,p62=1,p63=1,p64=1', you are all set. Otherwise you will need to enable http commands in the Web Console for your IP Power 9258 unit. Visit http://192.168.0.5/system.htm to enable http commands. Your device may reboot and cut the power to anything connected when you change a setting!!

  1. Clone this repository, go into the newly created directory named ansible-ippower9258

  2. Edit the inventory file and change the IP address to your devices actual IP address.

That's it! Run the ippower-getstate.yml playbook to the state of the outlets.

Edit the ippower-setstate.yml file to set the outlets and their state. 0 = off, 1 = on.

Better yet, pass in extra-vars on the command line, or create a survery in Ansible Tower:

[syspimp@localhost ansible-ippower9258]$ ansible-playbook -i inventory ippower-getstate.yml 

PLAY [Get the power state of the IP Power 9258 unit] *****************************************************************

TASK [Get the state of all of the ports] *****************************************************************************
[WARNING]: The value ******** (type int) in a string field was converted to '********' (type string). If this does
not look like what you expect, quote the entire value to ensure it does not change.

ok: [192.168.0.5 -> localhost]

TASK [Creating dictionary from the output] ***************************************************************************
ok: [192.168.0.5] => (item=<html>p61=1)
ok: [192.168.0.5] => (item=p62=1)
ok: [192.168.0.5] => (item=p63=1)
ok: [192.168.0.5] => (item=p64=1</html>
)

TASK [Show the Parsed Output] ****************************************************************************************
ok: [192.168.0.5] => {
    "result": {
        "port1": "On",
        "port2": "On",
        "port3": "On",
        "port4": "On"
    }
}

PLAY RECAP ***********************************************************************************************************
192.168.0.5   : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[syspimp@localhost ansible-ippower9258]$

syspimp@localhost ansible-ippower9258]$ ansible-playbook -e '{"outlets":[{"outlet":"1","state":"0"},{"outlet":"2","state":"0"}]}' -i inventory ippower-setstate.yml 

PLAY [Set the power state of the IP Power 9258 outlets] **************************************************************

TASK [Set the state of the Outlets being changed] ********************************************************************
ok: [192.168.0.5 -> localhost] => (item={'outlet': '1', 'state': '0'})
ok: [192.168.0.5 -> localhost] => (item={'outlet': '2', 'state': '0'})
[WARNING]: The value ******** (type int) in a string field was converted to '********' (type string). If this does
not look like what you expect, quote the entire value to ensure it does not change.


TASK [Get the state of the Outlets] **********************************************************************************
ok: [192.168.0.5 -> localhost]

TASK [Creating dictionary from the output] ***************************************************************************
ok: [192.168.0.5] => (item=<html>p61=0)
ok: [192.168.0.5] => (item=p62=0)
ok: [192.168.0.5] => (item=p63=1)
ok: [192.168.0.5] => (item=p64=1</html>
)

TASK [Show the Final State of Outlets] *******************************************************************************
ok: [192.168.0.5] => {
    "result": {
        "port1": "Off",
        "port2": "Off",
        "port3": "On",
        "port4": "On"
    }
}

PLAY RECAP ***********************************************************************************************************
192.168.0.5   : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[syspimp@localhost ansible-ippower9258]$