0

Is it possible to run Ansible on a bare metal to install OS on multiple machines along with SW installation and CODE deployment?

Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79

2 Answers2

0

To install OS on bare metal by Ansible both 1) modules to control the bare metal hosts and 2) modules to prepare the provisioning infrastructure will be needed.

  1. There is the list of Remote Management modules including for example Hpilo. But, I'm not aware of any systemic list of Ansible modules to control bare metal.

  2. There are also Ansible modules to control well-known frameworks that provide provisioning infrastructure. For example Cobbler or OpenStack Ironic. But, that's not that important here. Such provisioning infrastructure can be built by any means, of course.

Unfortunately, the Baremetal section of "Infrastructure Platforms" is not very helpful and points to all Cloud modules.


Without available controlling module it's not possible to run Ansible on bare metal. On the managed host, Ansible needs preinstalled SW, enabled connection and escalation. FWIW, as an example, below is my script firstboot.sh to enable Ansible on FreeBSD.

#!/bin/sh

VERSION="1.0.0"
USERNAME="admin"

# Install packages
env ASSUME_ALWAYS_YES=YES pkg install security/sudo
env ASSUME_ALWAYS_YES=YES pkg install lang/perl5.30
env ASSUME_ALWAYS_YES=YES pkg install lang/python37
env ASSUME_ALWAYS_YES=YES pkg install security/py-openssl
env ASSUME_ALWAYS_YES=YES pkg install archivers/gtar

# Create user
if (! getent passwd ${USERNAME} > /dev/null); then
    if (pw useradd -n ${USERNAME} -s /bin/sh -m); then
    printf "[OK] user ${USERNAME} created\n"
    else
    printf "[ERR] can not create user ${USERNAME}\n"
    fi
else
    printf "[OK] user ${USERNAME} exists\n"
fi

# Create directories and files

# $HOME/.ssh
if [ ! -e /home/${USERNAME}/.ssh ]; then
    if (mkdir /home/${USERNAME}/.ssh); then
    printf "[OK] dir /home/${USERNAME}/.ssh created\n"
    else
    printf "[ERR] can not create dir /home/${USERNAME}/.ssh\n"
    fi
else
    printf "[OK] dir /home/${USERNAME}/.ssh exists\n"
fi
[ -e /home/${USERNAME}/.ssh ] && chmod 0700 /home/${USERNAME}/.ssh

# $HOME/.ssh/authorized_keys
[ ! -e /home/${USERNAME}/.ssh/authorized_keys ] && \
    touch /home/${USERNAME}/.ssh/authorized_keys
[ -e /home/${USERNAME}/.ssh/authorized_keys ] && \
    chmod 0600 /home/${USERNAME}/.ssh/authorized_keys
chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}

# Configure sudoers
cp /usr/local/etc/sudoers.dist /usr/local/etc/sudoers
chown root:wheel /usr/local/etc/sudoers
chmod 0440 /usr/local/etc/sudoers
echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> /usr/local/etc/sudoers

# EOF
Vladimir Botka
  • 3,791
  • 6
  • 17
0

Bare metal is possible, as a part of provisioning use cases. Ansible can run on many platforms and talk to many operating systems and orchestrator APIs. Examples:

  • Network playbooks to configure the desired IP networks.
  • Install and configure a network boot system to provision hosts.
  • Launch bare metal instances from your favorite IaaS provider.
  • Manage hypervisor clusters.
  • Run Ansible from each host as a part of a first boot configuration, perhaps with the ansible-pull wrapper script.
  • OS and application configuration playbooks.

You will need a Python interpreter to run Ansible, some credentials to systems, and some procedure that can be automated for it to do. Typically some management system is a prerequisite to get started, even if just a laptop to run Ansible from.

The amount of effort varies depending on what you are trying to do. Bare metal AWS EC2 instances can be spun up similar to virtual ones. A rack of hardware without a nice API may be quite a long playbook.

John Mahowald
  • 30,009
  • 1
  • 17
  • 32
  • In the "provisioning use cases", you recommended, the "Baremetal" section says "Ansible integrates with many datacenter management tools" `https://docs.ansible.com/ansible/latest/modules/list_of_cloud_modules.html` Is this really where one would like to start with baremetal? – Vladimir Botka Jul 24 '20 at 19:43
  • First you must decide on what infrastructure platform meets your needs. Consider what you would do without Ansible. An OpenStack deployment is a big project in multiple dimensions, for example. Then, see what Ansible content may already exist to help automate. Ansible is a generic framework to run commands on (remote) hosts. It can do anything... but some APIs are much easier to automate. – John Mahowald Jul 25 '20 at 15:49
  • The question is to *"install OS on bare metal"*. It seems you got it: *"what Ansible content may already exist to help automate"*. But, I don't see a single link to such content in your answer. I'd expect a list of Ansible remote management modules to help me choose the infrastructure platform. The fact that [Baremetal](https://www.ansible.com/use-cases/provisioning) shows the list of [Cloud modules](https://docs.ansible.com/ansible/latest/modules/list_of_cloud_modules.html) must be a mistake. (Other explanation would be a bad joke.) – Vladimir Botka Jul 25 '20 at 16:19
  • What platform or provider specifically are you considering? Bootloaders, OOB management, and other details are different between x86, POWER, and other architectures. Admittedly, there might not be many examples of bare metal due to this messiness in bootstrapping. The "cloud" category is extremely nebulous, as it includes most of the physical and virtual host management. Some of that is marketing checking all the boxes, but you can drive anything you can ssh into or hit the API of. – John Mahowald Jul 25 '20 at 16:53
  • You say "there might not be many examples of bare metal". If you decided to answer here show a link to at least one. This will be at least a hint of what might be available. I simply try to find the shortest path to such info. That's what this site is for. Right? – Vladimir Botka Jul 25 '20 at 17:13