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;

- hosts: localhost
  connection: local
  gather_facts: no
  - name: "PASSWORD"
    prompt: "Password for superone IPMI?"
    private: yes
  - name: switch
      port: 80
      timeout: 10
  - name: superone-bmc network
      port: 80
  - name: superone-bmc power
      user: ADMIN
      password: "{{ PASSWORD }}"
      state: on
  - name: superone ping
      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 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?


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.