2
\$\begingroup\$

This is an ansible playbook that I use for powering on one of my home servers in a rack, that I just turn on when needed. It checks for the switch power, management (bmc) network, powers the server on, then waits for the SSH port to become available.

The playbook;

#!/usr/bin/ansible-playbook
---
- hosts: localhost
  connection: local
  gather_facts: no
  vars_prompt:
  - name: "PASSWORD"
    prompt: "Password for superone IPMI?"
    private: yes
  tasks:
  - name: switch
    wait_for: 
      host: 192.168.66.4
      port: 80
      timeout: 10
  - name: superone-bmc network
    wait_for: 
      host: 192.168.66.7
      port: 80
  - name: superone-bmc power
    ipmi_power: 
      name: 192.168.66.7
      user: ADMIN
      password: "{{ PASSWORD }}"
      state: on
  - name: superone ping
    wait_for: 
      host: 192.168.66.10
      port: 22

I'm looking for your guidance to optimize around the following issues I see in this playbook;

1st concern: "Localhost" referenced when I run it. This is because the ansible connection is local, and I'm not specifying any ansible hosts, but it means these status messages are of absolutely no use;

PLAY [localhost] ****...

TASK [switch] ****...
ok: [localhost]

TASK [server-bmc interface] ****...
ok: [localhost]

2nd concern; If the server is already on (the final ping to 192.168.66.10 succeeds), I've just run a bunch of tasks that were unnecessary. I almost want to run the tasks in reverse, see what fails, then start from there.

This isn't a worry for this short script, but as I'm learning Ansible and writing more complex playbooks, I don't want to waste time with tasks that are unnecessary.

3rd concern: Is anything I'm doing not very Ansible-like, does anything go against Ansible best practices?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.