From 7e26bdc6f571a3b1c68c44e9886bc138b9266034 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sun, 13 Dec 2015 09:12:19 +0200
Subject: [PATCH] Added support for bootstrapping OpenBSD (for running Ansible
 in the first place).

---
 tasks/main.yml              |  3 +++
 tasks/openbsd_bootstrap.yml | 30 ++++++++++++++++++++++++++++++
 vars/main.yml               |  2 ++
 3 files changed, 35 insertions(+)
 create mode 100644 tasks/openbsd_bootstrap.yml

diff --git a/tasks/main.yml b/tasks/main.yml
index 8d31a1f..78242c4 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,6 +1,9 @@
 ---
 # tasks file for ansible_common
 
+- include: openbsd_bootstrap.yml
+  when: openbsd_bootstrap is defined
+
 - name: Assert
   assert:
     that: ansible_os_family in [ 'Debian', 'OpenBSD' ]
diff --git a/tasks/openbsd_bootstrap.yml b/tasks/openbsd_bootstrap.yml
new file mode 100644
index 0000000..9d14194
--- /dev/null
+++ b/tasks/openbsd_bootstrap.yml
@@ -0,0 +1,30 @@
+---
+# Bootstrap an OpenBSD machine to be able to run Ansible on it.
+
+- name: Install Python
+  raw: "PKG_PATH={{ openbsd_pkg_mirror }}/OpenBSD/$(uname -r)/packages/$(arch -s)/ /usr/sbin/pkg_add py-pip"
+  register: openbsd_pkg_add_python
+  changed_when: "'python' in openbsd_pkg_add_python.stdout"
+
+- name: Symlink python
+  file:
+    path: /usr/bin/python
+    src: /usr/local/bin/python2.7
+    state: link
+    force: yes
+
+- name: Gather facts
+  setup:
+
+- name: Configure pkg
+  lineinfile:
+    dest: /etc/pkg.conf
+    line: 'installpath = {{ openbsd_pkg_mirror }}/OpenBSD/{{ ansible_distribution_release }}/packages/{{ ansible_architecture }}/'
+    regexp: '^installpath ='
+    state: present
+    create: yes
+
+- name: Install Bash
+  openbsd_pkg:
+    name: bash
+    state: latest
diff --git a/vars/main.yml b/vars/main.yml
index 77c074f..1b3dc60 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -30,3 +30,5 @@ openbsd_collectd_version:
     '5.6': 'collectd-4.10.2p4'
     '5.7': 'collectd-5.4.1p1'
     '5.8': 'collectd-5.5.0p1'
+
+openbsd_pkg_mirror: http://www.mirrorservice.org/pub
-- 
GitLab