Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CDK installation on Mac OS X #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 11 additions & 6 deletions cdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@
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

- include: tasks/clean_up.yml
tags: uninstall
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 }}
20 changes: 20 additions & 0 deletions files/registration-skip-k8s.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

OS=`uname`

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
20 changes: 20 additions & 0 deletions files/registration-skip-ose.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

OS=`uname`

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
19 changes: 14 additions & 5 deletions files/vagrant-up-k8s.sh.j2
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#!/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`

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
19 changes: 14 additions & 5 deletions files/vagrant-up-ose.sh.j2
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#!/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`

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
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
13 changes: 11 additions & 2 deletions group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ 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
- rhel-server-rhscl-7-rpms

rhel_pkgs:
- libvirt
- sclo-vagrant1
- libxml2-devel
- libvirt-devel
- sclo-vagrant1-vagrant-1.7.4-3.el7.noarch # vagrant 1.8.1 does not work with bundled plugins in CDK.
- sclo-vagrant1-vagrant-libvirt
- sclo-vagrant1-vagrant-libvirt-doc
- sclo-vagrant1-vagrant-registration
Expand Down Expand Up @@ -52,3 +54,10 @@ 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
box_name: "{{ vagrant_box_name|default('cdkv2') }}"
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
;;
2)
ansible-playbook -i ../ansible_inventory.txt ../cdk.yml -t setup,fedora
;;
3)
ansible-playbook -i ../ansible_inventory.txt ../cdk.yml -t setup,osx
;;
*)
echo "Unable to install on specified operating system"
;;
esac
2 changes: 1 addition & 1 deletion scripts/switch-box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ while true; do
"ose" ) cd ~/cdk/components/rhel/rhel-ose; vagrant ssh; cd ~;;
* ) echo "Un-supported input"
esac
done
done
2 changes: 1 addition & 1 deletion tasks/cdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@

- name: fedora - vagrant add libvirt box
shell: vagrant box add --name cdkv2 *libvirt.box
when: ansible_distribution == 'Fedora' and ansible_distribution_version == '23'
when: ansible_distribution == 'Fedora' and ansible_distribution_version == '23'
85 changes: 85 additions & 0 deletions tasks/clean_up.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
- name: destroy rhel-ose
shell: . /opt/rh/sclo-vagrant1/enable \
vagrant destroy -f
chdir=~/cdk/components/rhel/rhel-ose
become: yes
become_user: "{{ username }}"
when: ansible_distribution == 'RedHat' and ansible_distribution_version >= '7.2'

- name: destroy rhel-k8s
shell: . /opt/rh/sclo-vagrant1/enable \
vagrant destroy -f
chdir=~/cdk/components/rhel/misc/rhel-k8s-singlenode-setup
become: yes
become_user: "{{ username }}"
when: ansible_distribution == 'RedHat' and ansible_distribution_version >= '7.2'

- name: vagrant remove box
shell: . /opt/rh/sclo-vagrant1/enable \
vagrant box remove "{{ box_name }}"
become: yes
become_user: "{{ username }}"
when: ansible_distribution == 'RedHat' and ansible_distribution_version >= '7.2'

- name: uninstall vagrant plugins
shell: . /opt/rh/sclo-vagrant1/enable \
vagrant plugin uninstall vagrant-registration vagrant-service-manager vagrant-sshfs
become: yes
become_user: "{{ username }}"
when: ansible_distribution == 'RedHat' and ansible_distribution_version >= '7.2'

- name: destroy rhel-ose
shell: vagrant destroy -f
chdir=~/cdk/components/rhel/rhel-ose
become: yes
become_user: "{{ username }}"
when: (ansible_distribution == 'Fedora' and ansible_distribution_version == '23') or
(ansible_distribution == 'MacOSX')

- name: destroy rhel-k8s
shell: vagrant destroy -f
chdir=~/cdk/components/rhel/misc/rhel-k8s-singlenode-setup
become: yes
become_user: "{{ username }}"
when: (ansible_distribution == 'Fedora' and ansible_distribution_version == '23') or
(ansible_distribution == 'MacOSX')

- name: vagrant remove box
shell: vagrant box remove "{{ box_name }}"
become: yes
become_user: "{{ username }}"
when: (ansible_distribution == 'Fedora' and ansible_distribution_version == '23') or
(ansible_distribution == 'MacOSX')

- name: uninstall vagrant plugins
shell: vagrant plugin uninstall vagrant-registration vagrant-service-manager vagrant-sshfs
become: yes
become_user: "{{ username }}"
when: (ansible_distribution == 'Fedora' and ansible_distribution_version == '23') or
(ansible_distribution == 'MacOSX')

- name: userdel "{{ username }}"
user: name="{{ username }}" state=absent remove=yes force=yes
become: yes
become_user: root
when: (ansible_distribution == 'Fedora' and ansible_distribution_version == '23') or
(ansible_distribution == 'RedHat' and ansible_distribution_version >= '7.2')

- name: yum_remove | installed rpms
yum: name={{ item }} state=removed disable_gpg_check=yes
with_items: "{{ rhel_pkgs }}"
when: rhel_pkgs is defined and rhel_pkgs|length > 0 and
(ansible_distribution == 'Fedora' and ansible_distribution_version == '23') or
(ansible_distribution == 'RedHat' and ansible_distribution_version >= '7.2')

- name: osx - remove {{ username }} user
shell: /usr/bin/dscl . -delete "/Users/{{ username }}"
when: ansible_distribution == 'MacOSX'
become: yes
become_user: root

- name: osx - remove {{ username }} user directory
file: path=/Users/"{{ username }}" state=absent
when: ansible_distribution == 'MacOSX'
become: yes
become_user: root
Empty file added tasks/dependency.yml
Empty file.
2 changes: 1 addition & 1 deletion tasks/dnf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
dnf: name=* state=latest disable_gpg_check=yes

- name: install virtualization group
dnf: name="@Virtualization" state=present disable_gpg_check=yes
dnf: name="@Virtualization" state=present disable_gpg_check=yes
Loading