Skip to content

Commit

Permalink
Support CDK installation on Mac OS X
Browse files Browse the repository at this point in the history
Extend support to install CDK on Mac OS X
  • Loading branch information
gsr-shanks committed Jul 4, 2016
1 parent 4d6f486 commit cc8f7e1
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 25 deletions.
1 change: 1 addition & 0 deletions ansible_inventory.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
localhost ansible_connection=local

[cdk]
localhost ansible_connection=local
13 changes: 7 additions & 6 deletions cdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
tasks:
- include: tasks/rhn_register.yml
when: ansible_os_family == 'RedHat' and ansible_distribution_version >= '7.2' and rhn_method is defined
tags: setup, rhel
- include: tasks/yum.yml
when: ansible_distribution == 'RedHat' and ansible_distribution_version >= '7.2'
tags: setup, rhel

- include: tasks/dnf.yml
when: ansible_distribution == 'Fedora' and ansible_distribution_version >= '23'
tags: setup, fedora

- include: tasks/prereq.yml

- include: tasks/cdk.yml
become: yes
become_user: cdk
tags: setup, rhel, fedora, osx

- include: tasks/vagrant.yml
become: yes
become_user: cdk
become_user: "{{ username }}"
environment:
SUB_USERNAME: "{{ rhn_username }}"
SUB_PASSWORD: "{{ rhn_password }}"
SUB_PASSWORD: "{{ rhn_password }}"
tags: setup, rhel, fedora, osx
13 changes: 13 additions & 0 deletions files/osx-newuser.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
. /etc/rc.common
dscl . create /Users/{{ username }}
dscl . create /Users/{{ username }} hint '{{ password | replace("'", "'\\''") | truncate(4, True) }}'
dscl . passwd /Users/{{ username }} '{{ password | replace("'", "'\\''") }}'
dscl . create /Users/{{ username }} UniqueID {{ uid.stdout }}
dscl . create /Users/{{ username }} PrimaryGroupID 20
dscl . create /Users/{{ username }} UserShell /bin/bash
dscl . create /Users/{{ username }} NFSHomeDirectory /Users/{{ username }}
cp -R /System/Library/User\ Template/English.lproj /Users/{{ username }}
chown -R {{ username }}:staff /Users/{{ username }}

dscl . append /Groups/admin GroupMembership {{ username }}
24 changes: 24 additions & 0 deletions files/registration-skip-k8s.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

OS=`uname`
pushd ~/cdk/components/rhel/misc/rhel-k8s-singlenode-setup

case "$OS" in
Linux)
sed -i '$i config.registration.skip = true' Vagrantfile
;;
Darwin)
gsed -i '$i config.registration.skip = true' Vagrantfile
;;
esac


if [ -f /etc/redhat-release ]; then
if grep -i fedora /etc/redhat-release; then
vagrant up
elif grep -i 'red hat' /etc/redhat-release; then
scl enable sclo-vagrant1 'bash -c "vagrant up"'
fi
fi

popd
23 changes: 23 additions & 0 deletions files/registration-skip-ose.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

OS=`uname`
pushd ~/cdk/components/rhel/rhel-ose

case "$OS" in
Linux)
sed -i '$i config.registration.skip = true' Vagrantfile
;;
Darwin)
gsed -i '$i config.registration.skip = true' Vagrantfile
;;
esac

if [ -f /etc/redhat-release ]; then
if grep -i fedora /etc/redhat-release; then
vagrant up
elif grep -i 'red hat' /etc/redhat-release; then
scl enable sclo-vagrant1 'bash -c "vagrant up"'
fi
fi

popd
23 changes: 18 additions & 5 deletions files/vagrant-up-k8s.sh.j2
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#!/usr/bin/env bash

cd /home/cdk/cdk/components/rhel/misc/rhel-k8s-singlenode-setup
sed -i '$i config.registration.serverurl = "{{ rhn_server_hostname }}"' Vagrantfile
sed -i '$i config.registration.baseurl = "{{ rhsm_baseurl }}"' Vagrantfile
OS=`uname`
pushd ~/cdk/components/rhel/misc/rhel-k8s-singlenode-setup

case "$OS" in
Linux)
sed -i '$i config.registration.serverurl = "{{ rhn_server_hostname }}"' Vagrantfile
sed -i '$i config.registration.baseurl = "{{ rhsm_baseurl }}"' Vagrantfile
;;
Darwin)
gsed -i '$i config.registration.serverurl = "{{ rhn_server_hostname }}"' Vagrantfile
gsed -i '$i config.registration.baseurl = "{{ rhsm_baseurl }}"' Vagrantfile
;;
esac


if grep -i fedora /etc/redhat-release; then
vagrant up
else
elif grep -i 'red hat' /etc/redhat-release; then
scl enable sclo-vagrant1 'bash -c "vagrant up"'
fi
fi

popd
23 changes: 18 additions & 5 deletions files/vagrant-up-ose.sh.j2
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#!/usr/bin/env bash

cd /home/cdk/cdk/components/rhel/rhel-ose
sed -i '$i config.registration.serverurl = "{{ rhn_server_hostname }}"' Vagrantfile
sed -i '$i config.registration.baseurl = "{{ rhsm_baseurl }}"' Vagrantfile
OS=`uname`
pushd ~/cdk/components/rhel/rhel-ose

case "$OS" in
Linux)
sed -i '$i config.registration.serverurl = "{{ rhn_server_hostname }}"' Vagrantfile
sed -i '$i config.registration.baseurl = "{{ rhsm_baseurl }}"' Vagrantfile
;;
Darwin)
gsed -i '$i config.registration.serverurl = "{{ rhn_server_hostname }}"' Vagrantfile
gsed -i '$i config.registration.baseurl = "{{ rhsm_baseurl }}"' Vagrantfile
;;
esac


if grep -i fedora /etc/redhat-release; then
vagrant up
else
elif grep -i 'red hat' /etc/redhat-release; then
scl enable sclo-vagrant1 'bash -c "vagrant up"'
fi
fi

popd
16 changes: 14 additions & 2 deletions files/wget_latest_cdk_build.sh.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#!/usr/bin/env bash

wget -A zip,ks,vagrant-libvirt.box -r --no-parent -l1 -nd --reject="index.html*" {{ cdk_location }}
unzip *.zip
OS=`uname`

case "$OS" in
Linux)
wget -A zip,ks,vagrant-libvirt.box -r --no-parent -l1 -nd --reject="index.html*" {{ cdk_location }}
;;
Darwin)
wget -A zip,ks,vagrant-virtualbox.box -r --no-parent -l1 -nd --reject="index.html*" {{ cdk_location }}
;;
esac

if [ -f "cdk.zip" ]; then
unzip cdk.zip
fi
8 changes: 7 additions & 1 deletion group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rhn_server_hostname: subscription.rhn.stage.redhat.com

rhn_server_insecure: false
autosubscribe: true
rhsm_baseurl: https://cdn.qa.redhat.com
rhsm_baseurl: http://cdn.stage.redhat.com
rhsm_repos:
- rhel-7-server-rpms
- rhel-7-server-optional-rpms
Expand Down Expand Up @@ -52,3 +52,9 @@ enabled_repos:
disabled_repos: []
skipped_repos:
- rhel-7-server-rt-beta-rpms


# ~~~ Extra variables
registration_skip: "{{ skip_registration|default('true') }}"
username: "{{ user_name|default('cdk') }}"
password: redhat
21 changes: 20 additions & 1 deletion scripts/install-cdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,23 @@

export ANSIBLE_SSH_CONTROL_PATH='%(directory)s/%%h-%%r'
export ANSIBLE_HOST_KEY_CHECKING="False"
ansible-playbook -i ../ansible_inventory.txt ../cdk.yml

echo "1. Red Hat Enterprise Linux"
echo "2. Fedora"
echo "3. Mac OS X"
read -p "Select operating system option to install Container Development Kit: " OS

case "$OS" in
1)
ansible-playbook -i ../ansible_inventory.txt ../cdk.yml -t setup,rhel -e "skip_registration=true"
;;
2)
ansible-playbook -i ../ansible_inventory.txt ../cdk.yml -t setup,fedora -e "skip_registration=true"
;;
3)
ansible-playbook -i ../ansible_inventory.txt ../cdk.yml -t setup,osx -e "skip_registration=true"
;;
*)
echo "Unabled to install on specified operating system"
;;
esac
67 changes: 66 additions & 1 deletion tasks/prereq.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
---

- include: ../handlers/restart_services.yml
when: (ansible_distribution == 'Fedora' and ansible_distribution_version == '23') or
(ansible_distribution == 'RedHat' and ansible_distribution_version >= '7.2')
tags: setup, rhel, fedora

- name: check cpuinfo for vmx or svm
command: grep -iE 'vmx|svm' /proc/cpuinfo
when: (ansible_distribution == 'Fedora' and ansible_distribution_version == '23') or
(ansible_distribution == 'RedHat' and ansible_distribution_version >= '7.2')
tags: setup, rhel, fedora

- name: check cpuinfo for vmx on osx
shell: sysctl -a | grep machdep.cpu.features | grep VMX
when: ansible_distribution == 'MacOSX'
tags: setup, osx

- name: copy vagrant-libvirt-rules
shell: cp /opt/rh/sclo-vagrant1/root/usr/share/vagrant/gems/doc/vagrant-libvirt-*/polkit/10-vagrant-libvirt.rules
Expand All @@ -12,6 +23,7 @@
notify:
- restart libvirtd
- restart polkit
tags: setup, rhel

- name: copy vagrant-libvirt-rules
shell: cp /usr/share/vagrant/gems/doc/vagrant-libvirt-*/polkit/10-vagrant-libvirt.rules
Expand All @@ -20,6 +32,59 @@
notify:
- restart libvirtd
- restart polkit
tags: setup, fedora

- name: create cdk user and add it to vagrant group
user: name=cdk shell=/bin/bash groups=vagrant append=yes
user: name={{ username }} shell=/bin/bash groups=vagrant append=yes
when: (ansible_distribution == 'Fedora' and ansible_distribution_version == '23') or
(ansible_distribution == 'RedHat' and ansible_distribution_version >= '7.2')
tags: setup, rhel, fedora

- name: osx - check if user exists
stat: path=/Users/{{ username }}
register: check_user
when: ansible_distribution == 'MacOSX'
tags: setup, osx

- name: osx - get next available User ID
shell: "echo $(dscl . -list /Users uid | awk '{print $2}' | sort -ug | tail -1) + 1 | bc"
register: uid
when: ansible_distribution == 'MacOSX'
tags: setup, osx

- name: osx - make temp for user scripts
command: mktemp /tmp/create_{{ username }}-XXXXX
register: newuser_script
when: ansible_distribution == 'MacOSX'
tags: setup, osx

- name: osx - create user script
template: src=files/osx-newuser.sh.j2 dest={{ newuser_script.stdout }} mode=0755
when: ansible_distribution == 'MacOSX'
tags: setup, osx

- name: osx - create user!
shell: "{{ newuser_script.stdout }} creates=/Users/{{ username }}"
become: yes
become_user: root
when: ansible_distribution == 'MacOSX'
tags: setup, osx

#- name: osx - Remove the newuser script
# file: path={{ newuser_script.stdout }} state=absent
# when: ansible_distribution == 'MacOSX'
# tags: setup, osx

- name: osx - Prepend /usr/local/bin to $PATH in .profile
lineinfile:
dest=/Users/{{ username }}/.profile
state=present
regexp="^export\s+PATH=/usr/local/bin:\\$PATH"
insertafter=EOF
line="export
PATH=/usr/local/bin:$PATH"
create=yes
become: yes
become_user: root
when: ansible_distribution == 'MacOSX'
tags: setup, osx
Loading

0 comments on commit cc8f7e1

Please sign in to comment.