Created
April 11, 2018 03:42
-
-
Save nullstream/977b3369c27377b6d79a3a15a2ab79fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Ensure wxallowed in /usr/local in fstab | |
# Inventory should have for each obsd host: ansible_python_interpreter=/usr/local/bin/python become_method=doas | |
# | |
# ./bootstrap-openbsd-new.sh hostname user | |
ANSIBLE_USER=control | |
INVENTORY=hosts | |
# Add host key to known_hosts | |
ssh-keyscan -H $1 >> ~/.ssh/known_hosts | |
# Add host to inventory | |
echo $1 ansible_python_interpreter=/usr/local/bin/python become_method=doas >> $INVENTORY | |
# Prime doas | |
ansible $1 -i $INVENTORY -m raw -b -a "echo 'permit nopass :wheel as root' >> /etc/doas.conf" --become-method=su -kK -u $2 | |
# Setup installurl for packages. | |
ansible $1 -i $INVENTORY -m raw -a "doas sh -c 'echo 'https://cdn.openbsd.org/pub/OpenBSD/' > /etc/installurl'" --become-method=su -kK -u $2 | |
# Install python for ansible | |
ansible $1 -i $INVENTORY -m raw -a "doas pkg_add -z python-2" --become-method=su -kK -u $2 | |
# Setup python for use. | |
ansible $1 -i $INVENTORY -m raw -a "ln -sf /usr/local/bin/python2.7 /usr/local/bin/python; ln -sf /usr/local/bin/python2.7-2to3 /usr/local/bin/2to3 ; ln -sf /usr/local/bin/python2.7-config /usr/local/bin/python-config; ln -sf /usr/local/bin/pydoc2.7 /usr/local/bin/pydoc" -b --become-method=su -Kk -u $2 | |
# Create ansible user | |
ansible $1 -i $INVENTORY -m shell -a "useradd -c 'Ansible User' -d /home/${ANSIBLE_USER} -m -G wheel ${ANSIBLE_USER}" -b --become-method=doas -u $2 | |
KEY=`cat ~/.ssh/id_rsa.pub` | |
# Setup authorized_key for | |
ansible $1 -i $INVENTORY -m shell -a "mkdir -p ~${ANSIBLE_USER}/.ssh; echo ${KEY} >> ~${ANSIBLE_USER}/.ssh/authorized_keys ; chown control:control ~control/.ssh" --become-method=doas -kK -bu $2 | |
# Test ansible control. | |
ansible $1 -i $INVENTORY -m shell -a "touch /root/test; rm /root/test" -b --become-method=doas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment