diff --git a/iiab-install b/iiab-install new file mode 100755 index 000000000..52f4575ca --- /dev/null +++ b/iiab-install @@ -0,0 +1,74 @@ +#!/bin/bash -e +# running from a git repo +PLAYBOOK="iiab-steps.yml" +INVENTORY="ansible_hosts" +CWD=`pwd` +# Add cmdline options for passing to ansible +# todo add proper shift to gobble up --debug --reinstall +ARGS="" + +export ANSIBLE_LOG_PATH="$CWD/iiab-install.log" + +if [ ! -f /etc/ansible/facts.d/local_facts.fact ]; then + mkdir -p /etc/ansible/facts.d +fi +cp ./scripts/local_facts.fact /etc/ansible/facts.d/local_facts.fact + +STAGE="" + +if [ ! -f /etc/iiab/iiab.env ]; then + mkdir -p /etc/iiab +else + OLD=`grep XSCE /etc/iiab/iiab.env | wc -l` + if [ "$OLD" != 0 ] || [ "$1" = "--reinstall" ]; then + echo "Found old XSCE install - re-installing from scratch" + rm /etc/iiab/iiab.env + # check ansible version here and force ansible upgrade if needed + else + source /etc/iiab/iiab.env + if [ $STAGE == 9 ] && [ "$1" = "--debug" ]; then + echo "Entering debug mode" + sed -i -e 's/^STAGE=.*/STAGE=2/' /etc/iiab/iiab.env + elif [ ! $STAGE == 9 ]; then + echo "Restarting from STAGE $STAGE" + else + # place keeper add read response + # "offer 'Y' or stage number dialog box option to override" + echo "'iiab-install' has already been completed" + echo "use --debug to override " + #echo "In demo mode not preventing second run" + echo "Exiting." + exit 1 + fi + fi +fi + +if [ ! -f $PLAYBOOK ]; then + echo "IIAB Playbook not found." + echo "Please run this command from the top level of the git repo." + echo "Exiting." + exit 1 +fi + +# if vars/local_vars.yml is missing, put a default one in place - First Run +if [ ! -f ./vars/local_vars.yml ]; then + OS=`grep ^ID= /etc/*release|cut -d= -f2` + OS=${OS//\"/} + + case $OS in + OLPC | fedora) + cp ./vars/olpc.localvars ./vars/local_vars.yml + ;; + centos | debian | ubuntu | raspbian) + cp ./vars/medium.localvars ./vars/local_vars.yml + ;; + *) + echo "IIAB supports raspbian, debian, ubuntu, centos, and OLPC - exiting now..." + exit 1 + ;; + esac +fi + +echo "Running local playbooks! " +ansible -m setup -i $INVENTORY localhost --connection=local >> /dev/null +ansible-playbook -i $INVENTORY $PLAYBOOK ${ARGS} --connection=local diff --git a/iiab-network b/iiab-network index 9e24154be..feb2e3ac9 100755 --- a/iiab-network +++ b/iiab-network @@ -1,15 +1,8 @@ #!/bin/bash - -if [ -f /etc/iiab/iiab.env ] -then - . /etc/iiab/iiab.env - cd $IIAB_DIR -else - echo /etc/iiab/iiab.env is missing. Playbook has not been run. - exit 1 -fi - +# running from a git repo +# ansible files exist CWD=`pwd` +export ANSIBLE_LOG_PATH="$CWD/iiab-network.log" if [ ! -f iiab-network.yml ] then @@ -24,7 +17,6 @@ then touch /etc/iiab/config_vars.yml fi -export ANSIBLE_LOG_PATH="$CWD/iiab-network.log" ansible-playbook -i ansible_hosts iiab-network.yml --connection=local echo "" >> iiab-network.log ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log diff --git a/iiab-steps.yml b/iiab-steps.yml new file mode 100644 index 000000000..66c97721c --- /dev/null +++ b/iiab-steps.yml @@ -0,0 +1,29 @@ +--- +- hosts: all + become: yes + + vars_files: + - vars/default_vars.yml + - vars/{{ ansible_local.local_facts.os_ver }}.yml + - vars/local_vars.yml + + roles: + - { role: 0-init, tags: ['0-init'] } + - { role: 1-prep, tags: ['1-prep','platform','base'], + when: ansible_local.local_facts.stage|int < 1 } + - { role: 2-common, tags: ['2-common','base'], + when: ansible_local.local_facts.stage|int < 2 } + - { role: 3-base-server, tags: ['3-base-server','base'], + when: ansible_local.local_facts.stage|int < 3 } + - { role: 4-server-options, tags: ['4-server-options'], + when: ansible_local.local_facts.stage|int < 4 } + - { role: 5-xo-services, tags: ['5-xo-services'], + when: ansible_local.local_facts.stage|int < 5 } + - { role: 6-generic-apps, tags: ['6-generic-apps'], + when: ansible_local.local_facts.stage|int < 6 } + - { role: 7-edu-apps, tags: ['7-edu-apps'], + when: ansible_local.local_facts.stage|int < 7 } + - { role: 8-mgmt-tools, tags: ['8-mgmt-tools'], + when: ansible_local.local_facts.stage|int < 8 } + - { role: 9-local-addons, tags: ['9-local-addons'], + when: ansible_local.local_facts.stage|int < 9 } diff --git a/install-support b/install-support index b7df01489..79439f2f7 100755 --- a/install-support +++ b/install-support @@ -4,6 +4,8 @@ PLAYBOOK="iiab-base.yml" INVENTORY="ansible_hosts" CWD=`pwd` +export ANSIBLE_LOG_PATH="$CWD/iiab-install.log" + if [ ! -f $PLAYBOOK ] then echo "IIAB Playbook not found." @@ -15,5 +17,4 @@ fi sed -i -e "s/openvpn_install: False/openvpn_install: True/" vars/local_vars.yml sed -i -e "s/openvpn_enabled: False/openvpn_enabled: True/" vars/local_vars.yml -export ANSIBLE_LOG_PATH="$CWD/iiab-install.log" ansible-playbook -i $INVENTORY $PLAYBOOK --connection=local diff --git a/roles/1-prep/tasks/computed_vars.yml b/roles/1-prep/tasks/computed_vars.yml index ae53e7970..28ba861d6 100644 --- a/roles/1-prep/tasks/computed_vars.yml +++ b/roles/1-prep/tasks/computed_vars.yml @@ -6,8 +6,9 @@ # set top level variables from local facts for convenience - set_fact: - xo_model: '{{ ansible_local["local_facts"]["xo_model"] }}' - phplib_dir: '{{ ansible_local["local_facts"]["phplib_dir"] }}' + xo_model: '{{ ansible_local.local_facts.xo_model }}' + phplib_dir: '{{ ansible_local.local_facts.phplib_dir }}' + iiab_stage: '{{ ansible_local.local_facts.stage }}' - name: Set exFAT enabled for XO laptops set_fact: @@ -46,33 +47,6 @@ file: path=/tmp/heart-beat.txt state=absent -- name: add version section - ini_file: dest='{{ iiab_config_file }}' - section=runtime - option='{{ item.option }}' - value='{{ item.value }}' - with_items: - - option: 'runtime_branch' - value: '{{ ansible_local["local_facts"]["iiab_branch"] }}' - - option: 'runtime_commit' - value: '{{ ansible_local["local_facts"]["iiab_commit"] }}' - - option: 'runtime_date' - value: '{{ ansible_date_time["iso8601"] }}' - - option: 'runtime_php' - value: '{{ phplib_dir }}' - - option: 'kernel' - value: '{{ ansible_kernel }}' - - option: 'memory_mb' - value: '{{ ansible_memtotal_mb }}' - - option: 'swap_mb' - value: '{{ ansible_swaptotal_mb }}' - - option: 'product_id' - value: '{{ ansible_product_uuid }}' - - option: 'gw_active' - value: '{{ gw_active }}' - - option: 'internet_available' - value: '{{ internet_available }}' - # Put all computed vars here so derive properly from any prior var file - name: If the TZ is not set in env, set it to UTC set_fact: local_tz='UTC' @@ -176,3 +150,34 @@ set_fact: is_CentOS: True when: ansible_distribution == "CentOS" + +- name: add version section + ini_file: dest='{{ iiab_config_file }}' + section=runtime + option='{{ item.option }}' + value='{{ item.value }}' + with_items: + - option: 'iiab_stage' + value: '{{ iiab_stage }}' + - option: 'runtime_php' + value: '{{ phplib_dir }}' + - option: 'runtime_branch' + value: '{{ ansible_local.local_facts.iiab_branch }}' + - option: 'runtime_commit' + value: '{{ ansible_local.local_facts.iiab_commit }}' + - option: 'runtime_date' + value: '{{ ansible_date_time.iso8601 }}' + - option: 'ansible_version' + value: '{{ ansible_local.local_facts.ansible_version }}' + - option: 'kernel' + value: '{{ ansible_kernel }}' + - option: 'memory_mb' + value: '{{ ansible_memtotal_mb }}' + - option: 'swap_mb' + value: '{{ ansible_swaptotal_mb }}' + - option: 'product_id' + value: '{{ ansible_product_uuid }}' + - option: 'gw_active' + value: '{{ gw_active }}' + - option: 'internet_available' + value: '{{ internet_available }}' diff --git a/roles/1-prep/tasks/main.yml b/roles/1-prep/tasks/main.yml index e6e2b382a..84ae926eb 100644 --- a/roles/1-prep/tasks/main.yml +++ b/roles/1-prep/tasks/main.yml @@ -1,6 +1,6 @@ # Preparations (Hardware Level) -- name: ...IS BEGINNING ============================================ +- name: ...IS BEGINNING ================================== command: echo - name: Get the uuidgen program @@ -88,5 +88,10 @@ url={{ iiab_download_url }}/iwlwifi-8000C-13.ucode when: first_run and usb_NUC6.stdout|int > 0 -- name: ...HAS COMPLETED =========================================== - command: echo +# this script can be sourced to get IIAB location +- name: Recording STAGE 1 HAS COMPLETED ================== + template: src=roles/1-prep/templates/iiab.env.j2 + dest=/etc/iiab/iiab.env + owner=root + group=root + mode=0644 diff --git a/roles/1-prep/templates/iiab.env.j2 b/roles/1-prep/templates/iiab.env.j2 index b472d4fe6..423c13ec6 100644 --- a/roles/1-prep/templates/iiab.env.j2 +++ b/roles/1-prep/templates/iiab.env.j2 @@ -1,7 +1,8 @@ -# This is a configuration file for XSCE +# This is a configuration file for IIAB # It can sourced in a shell script or read into an application IIAB_BASE_PATH={{ iiab_base }} IIAB_DIR={{ iiab_dir }} OS={{ ansible_local.local_facts.os }} OS_VER={{ ansible_local.local_facts.os_ver }} WWWROOT={{ doc_root }} +STAGE=1 diff --git a/roles/2-common/tasks/main.yml b/roles/2-common/tasks/main.yml index bfb69887b..acaacc99f 100644 --- a/roles/2-common/tasks/main.yml +++ b/roles/2-common/tasks/main.yml @@ -1,6 +1,6 @@ # Common OS-Level Additions & Mods (that only need to be performed once) -- name: ...IS BEGINNING ========================================== +- name: ...IS BEGINNING ================================== command: echo #- include: iiab_ini.yml @@ -48,5 +48,8 @@ - include: udev.yml -- name: ...HAS COMPLETED ========================================= - command: echo +- name: Recording STAGE 2 HAS COMPLETED ================== + lineinfile: dest=/etc/iiab/iiab.env + regexp='^STAGE=*' + line='STAGE=2' + state=present diff --git a/roles/3-base-server/tasks/main.yml b/roles/3-base-server/tasks/main.yml index 3aa90c43b..e59553e9e 100644 --- a/roles/3-base-server/tasks/main.yml +++ b/roles/3-base-server/tasks/main.yml @@ -1,6 +1,5 @@ # Base Server - -- name: ...IS BEGINNING ===================================== +- name: ...IS BEGINNING ================================== command: echo - name: HTTPD @@ -30,12 +29,9 @@ state=restarted when: not installing -# If we got here we're done -#- name: Record base gui version -# lineinfile: dest=/etc/iiab/iiab.env -# regexp='^BASE_VERSION=*' -# line='BASE_VERSION="{{ gui_version }}"' -# state=present +- name: Record STAGE 3 HAS COMPLETED ===================== + lineinfile: dest=/etc/iiab/iiab.env + regexp='^STAGE=*' + line='STAGE=3' + state=present -- name: ...HAS COMPLETED ==================================== - command: echo diff --git a/roles/4-server-options/tasks/main.yml b/roles/4-server-options/tasks/main.yml index 7efdffe74..2b68861eb 100644 --- a/roles/4-server-options/tasks/main.yml +++ b/roles/4-server-options/tasks/main.yml @@ -1,5 +1,4 @@ # Server Options - - name: ...IS BEGINNING ================================== command: echo @@ -57,14 +56,6 @@ when: usb_lib_install tags: usb-lib -# this script can be sourced to get IIAB location -- name: Create iiab.env file - template: src=roles/1-prep/templates/iiab.env.j2 - dest=/etc/iiab/iiab.env - owner=root - group=root - mode=0644 - - name: Put a Python interface to iiab.env template: src=roles/1-prep/templates/iiab_env.py.j2 dest=/etc/iiab/iiab_env.py @@ -73,5 +64,8 @@ command: /usr/bin/iiab-refresh-wiki-docs when: not nodocs -- name: ...HAS COMPLETED ================================= - command: echo +- name: Recording STAGE 4 HAS COMPLETED ================== + lineinfile: dest=/etc/iiab/iiab.env + regexp='^STAGE=*' + line='STAGE=4' + state=present diff --git a/roles/5-xo-services/tasks/main.yml b/roles/5-xo-services/tasks/main.yml index 2ee59d9e0..bc9c20653 100644 --- a/roles/5-xo-services/tasks/main.yml +++ b/roles/5-xo-services/tasks/main.yml @@ -1,6 +1,5 @@ # XO Services - -- name: ...IS BEGINNING ===================================== +- name: ...IS BEGINNING ================================== command: echo - name: ACTIVITY-SERVER @@ -21,5 +20,8 @@ when: idmgr_install tags: olpc, idmgr -- name: ...HAS COMPLETED ==================================== - command: echo +- name: Recording STAGE 5 HAS COMPLETED ================== + lineinfile: dest=/etc/iiab/iiab.env + regexp='^STAGE=*' + line='STAGE=5' + state=present diff --git a/roles/6-generic-apps/tasks/main.yml b/roles/6-generic-apps/tasks/main.yml index 6b4deeb49..9cf53a700 100644 --- a/roles/6-generic-apps/tasks/main.yml +++ b/roles/6-generic-apps/tasks/main.yml @@ -1,6 +1,5 @@ # Generic Apps - -- name: ...IS BEGINNING ==================================== +- name: ...IS BEGINNING ================================== command: echo - name: CALIBRE @@ -45,5 +44,8 @@ when: wordpress_install tags: wordpress -- name: ...HAS COMPLETED =================================== - command: echo +- name: Recording STAGE 6 HAS COMPLETED ================== + lineinfile: dest=/etc/iiab/iiab.env + regexp='^STAGE=*' + line='STAGE=6' + state=present diff --git a/roles/7-edu-apps/tasks/main.yml b/roles/7-edu-apps/tasks/main.yml index d484570b1..ee98a0d2d 100644 --- a/roles/7-edu-apps/tasks/main.yml +++ b/roles/7-edu-apps/tasks/main.yml @@ -1,6 +1,5 @@ # Educational Apps - -- name: ...IS BEGINNING ======================================== +- name: ...IS BEGINNING ================================== command: echo - name: KALITE @@ -39,5 +38,8 @@ when: sugarizer_install tags: sugarizer -- name: ...HAS COMPLETED ======================================= - command: echo +- name: Recording STAGE 7 HAS COMPLETED ================== + lineinfile: dest=/etc/iiab/iiab.env + regexp='^STAGE=*' + line='STAGE=7' + state=present diff --git a/roles/8-mgmt-tools/tasks/main.yml b/roles/8-mgmt-tools/tasks/main.yml index 01920102d..91413900b 100644 --- a/roles/8-mgmt-tools/tasks/main.yml +++ b/roles/8-mgmt-tools/tasks/main.yml @@ -1,6 +1,6 @@ # Assessment and Monitoring Tools -- name: ...IS BEGINNING ====================================== +- name: ...IS BEGINNING ================================== command: echo - name: AWSTATS @@ -51,5 +51,8 @@ when: xovis_install and ansible_distribution != "CentOS" tags: xovis -- name: ...HAS COMPLETED ===================================== - command: echo +- name: Recording STAGE 8 HAS COMPLETED ================== + lineinfile: dest=/etc/iiab/iiab.env + regexp='^STAGE=*' + line='STAGE=8' + state=present diff --git a/roles/9-local-addons/tasks/main.yml b/roles/9-local-addons/tasks/main.yml index 197bb3366..f518d6c81 100644 --- a/roles/9-local-addons/tasks/main.yml +++ b/roles/9-local-addons/tasks/main.yml @@ -1,7 +1,10 @@ # Local Add-ons -- name: ...IS BEGINNING ==================================== +- name: ...IS BEGINNING ============================= command: echo -- name: ...HAS COMPLETED =================================== - command: echo +- name: Recording STAGE 9 HAS COMPLETED ============= + lineinfile: dest=/etc/iiab/iiab.env + regexp='^STAGE=*' + line='STAGE=9' + state=present diff --git a/runtags b/runtags index b353d3a65..45ee507e7 100755 --- a/runtags +++ b/runtags @@ -1,16 +1,11 @@ #!/bin/bash +# running from a git repo PLAYBOOK="iiab.yml" INVENTORY="ansible_hosts" -# Pass cmdline options for ansible - -if [ -f /etc/iiab/iiab.env ] -then - . /etc/iiab/iiab.env - cd $IIAB_DIR -fi - CWD=`pwd` +export ANSIBLE_LOG_PATH="$CWD/iiab-debug.log" + if [ ! -f $PLAYBOOK ] then echo "IIAB Playbook not found." @@ -41,8 +36,6 @@ do fi done -# echo $found - taglist=$1 if [ "$found" == "N" ] @@ -50,5 +43,4 @@ then taglist="0-init,"$taglist fi -export ANSIBLE_LOG_PATH="$CWD/iiab-debug.log" ansible-playbook -i ansible_hosts iiab.yml --connection=local --tags="""$taglist""" diff --git a/scripts/local_facts.fact b/scripts/local_facts.fact index 4d9da02d6..54863bcd7 100755 --- a/scripts/local_facts.fact +++ b/scripts/local_facts.fact @@ -41,13 +41,24 @@ else XO_VERSION="none" fi +# upgrades return found, clean installs return 0 +# interruptions return last stage number recorded (1-9) +if [ -f /etc/iiab/iiab.env ] +then + STAGE=1 + source /etc/iiab/iiab.env + STAGE=$STAGE +else + STAGE=0 +fi ANSIBLE_VERSION=$(ansible --version|head -n 1|cut -f 2 -d " ") cat <