From c956f21343e67530b706edea59884bb11beeb768 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Wed, 22 Jul 2015 00:24:00 +0200 Subject: [PATCH] Using variables from domain.fact instead of local domain.yml. Managed in a different manner the different settings for the ubuntu mirror from VirtualBox and local server. --- roles/client-install/meta/main.yml | 1 - roles/init/tasks/domaininfo.yml | 8 ++++++-- roles/kickstart/tasks/kickstart.yml | 13 ++++++------ .../templates/post-ks/ansible-pull-crontab | 2 +- .../templates/post-ks/ansible-pull.sh | 6 +++--- .../templates/post-ks/getvaultpass.py | 2 +- roles/kickstart/templates/post-ks/post-ks.sh | 20 +++++++++---------- .../templates/profiles/client-trusty.cfg | 4 ++-- .../templates/profiles/docenti-trusty.cfg | 4 ++-- .../templates/profiles/ubuntu-trusty.cfg | 4 ++-- roles/nethcfg/tasks/reconfig_nic.yml | 4 ++-- roles/nethcfg/tasks/reconfig_srv.yml | 12 +++++------ roles/pxe/templates/pxelinux.cfg/default | 4 ++-- setup.yml | 2 -- 14 files changed, 44 insertions(+), 42 deletions(-) diff --git a/roles/client-install/meta/main.yml b/roles/client-install/meta/main.yml index e46985b..48f2039 100644 --- a/roles/client-install/meta/main.yml +++ b/roles/client-install/meta/main.yml @@ -1,6 +1,5 @@ --- dependencies: - - { role: domaininfo, tags: [ 'client-install', 'domaininfo' ] } - { role: pxe, tags: [ 'client-install', 'pxe' ] } - { role: kickstart, tags: [ 'client-install', 'kickstart', 'ks' ] } - { role: ubuntu-mirror, tags: [ 'client-install', 'ubuntu-mirror' ] } diff --git a/roles/init/tasks/domaininfo.yml b/roles/init/tasks/domaininfo.yml index 7198db4..e8824ed 100644 --- a/roles/init/tasks/domaininfo.yml +++ b/roles/init/tasks/domaininfo.yml @@ -4,6 +4,10 @@ copy: src=../../../domain.yml dest=/etc/domain.yml sudo: yes -- name: Utilizzo un piccolo wrapper per passare come fatti informazioni di dominio - copy: src=domain.fact dest=/etc/ansible/fact.d/domain.fact mode=0744 owner=root +- name: Creo la cartella per le configurazioni di Ansible + file: path=/etc/ansible/facts.d state=directory owner=root mode=0755 + sudo: yes + +- name: Utilizzo un piccolo wrapper per passare come fatti informazioni di dominio + copy: src=domain.fact dest=/etc/ansible/facts.d/domain.fact mode=0755 owner=root sudo: yes diff --git a/roles/kickstart/tasks/kickstart.yml b/roles/kickstart/tasks/kickstart.yml index b415109..bdf18f2 100644 --- a/roles/kickstart/tasks/kickstart.yml +++ b/roles/kickstart/tasks/kickstart.yml @@ -31,10 +31,15 @@ file: path=/var/lib/nethserver/ibay/ks/profiles state=directory sudo: yes -- name: Sovrascrivo la variabile mirrorpath se è su Virtualbox - set_fact: oldmirrorpath="{{ mirrorpath }}" mirrorpath="" +# Gestisco caso con virtualbox, dove non devo overridare il mirror +- name: ubuntumirrorpath per Virtualbox (no mirror) + set_fact: ubuntumirrorpath="" when: ansible_bios_version == "VirtualBox" +- name: ubuntumirrorpath per altro (usa mirror locale) + set_fact: ubuntumirrorpath="{{ ansible_local.domain.mirrorpath }}" + when: ansible_bios_version != "VirtualBox" + - name: Copia profili kickstart template: src=profiles/{{ item }} dest=/var/lib/nethserver/ibay/ks/profiles/{{ item }} sudo: yes @@ -52,10 +57,6 @@ - ansible-pull.sh - ansible-pull-crontab -- name: Ripristino impostazioni mirrorpath - set_fact: mirrorpath="{{ oldmirrorpath }}" - when: ansible_bios_version == "VirtualBox" - - name: Copio logrotate per configurazione pull copy: src=ansible-pull-logrotate dest=/var/lib/nethserver/ibay/ks/ansible-pull-logrotate sudo: yes diff --git a/roles/kickstart/templates/post-ks/ansible-pull-crontab b/roles/kickstart/templates/post-ks/ansible-pull-crontab index a313c67..3ab9a0b 100644 --- a/roles/kickstart/templates/post-ks/ansible-pull-crontab +++ b/roles/kickstart/templates/post-ks/ansible-pull-crontab @@ -1 +1 @@ -@reboot root /var/lib/{{ domainfull }}/bin/ansible-pull.sh >>/var/log/ansible-pull.log 2>&1 +@reboot root /var/lib/{{ ansible_local.domain.domainfull }}/bin/ansible-pull.sh >>/var/log/ansible-pull.log 2>&1 diff --git a/roles/kickstart/templates/post-ks/ansible-pull.sh b/roles/kickstart/templates/post-ks/ansible-pull.sh index ec0bac8..3f271ca 100644 --- a/roles/kickstart/templates/post-ks/ansible-pull.sh +++ b/roles/kickstart/templates/post-ks/ansible-pull.sh @@ -4,13 +4,13 @@ # Potremmo decidere di far eseguire uno script generato da servizio # domainhelper contenente anche l'eventuale branch da usare. -url=git://{{ serverfqdn }}/client-pull-installation.git -repo=/var/lib/{{ domainfull }}/config +url=git://{{ ansible_local.domain.serverfqdn }}/client-pull-installation.git +repo=/var/lib/{{ ansible_local.domain.domainfull }}/config logfile=/var/lib/ansible-pull.log branch=master playbook=local.yml -vaultpassfile=$(/var/lib/{{ domainfull }}/bin/getvaultpass.py) +vaultpassfile=$(/var/lib/{{ ansible_local.domain.domainfull }}/bin/getvaultpass.py) ansible-pull --accept-host-key -d "${repo}" -U "${url}" -C "${branch}" "${playbook}" --vault-password-file "${vaultpassfile}" rm -f "${vaultpassfile}" diff --git a/roles/kickstart/templates/post-ks/getvaultpass.py b/roles/kickstart/templates/post-ks/getvaultpass.py index a87a920..538cef4 100644 --- a/roles/kickstart/templates/post-ks/getvaultpass.py +++ b/roles/kickstart/templates/post-ks/getvaultpass.py @@ -11,7 +11,7 @@ import os key = MD5.new(gethostname()).digest() cipher = AES.new(key, AES.MODE_ECB) -base64enc = get("http://{{ serverfqdn }}:3000/vaultpass") +base64enc = get("http://{{ ansible_local.domain.serverfqdn }}:3000/vaultpass") encrypted = b64decode(base64enc.content) longpass = cipher.decrypt(encrypted) diff --git a/roles/kickstart/templates/post-ks/post-ks.sh b/roles/kickstart/templates/post-ks/post-ks.sh index 6d4b26d..f58dc20 100644 --- a/roles/kickstart/templates/post-ks/post-ks.sh +++ b/roles/kickstart/templates/post-ks/post-ks.sh @@ -1,35 +1,35 @@ #!/bin/bash # Cambio username con quello fornito da servizio -TARGETHOSTNAME=$(wget -qO- http://{{ serverfqdn }}:3000/whatsmyhostname) +TARGETHOSTNAME=$(wget -qO- http://{{ ansible_local.domain.serverfqdn }}:3000/whatsmyhostname) echo $TARGETHOSTNAME > /etc/hostname sed -i "s/kickseed/$TARGETHOSTNAME/g" /etc/hosts # Installo l'ultimo ansible per ansible-pull -export https_proxy=https://{{ serverip }}:3128 +export https_proxy=https://{{ ansible_local.domain.serverip }}:3128 add-apt-repository -y ppa:ansible/ansible apt-get update && apt-get install -y ansible unset https_proxy # Creo directory dipendenti -install -d -o root -g root /var/lib/{{ domainfull }}/config -install -d -o root -g root /var/lib/{{ domainfull }}/bin +install -d -o root -g root /var/lib/{{ ansible_local.domain.domainfull }}/config +install -d -o root -g root /var/lib/{{ ansible_local.domain.domainfull }}/bin # Installo lo script per la decrittazione della password del vault -wget -q http://{{ serverfqdn }}/ks/getvaultpass.py -O /tmp/getvaultpass.py -install -m744 -o root -g root /tmp/getvaultpass.py /var/lib/{{ domainfull}}/bin/getvaultpass.py +wget -q http://{{ ansible_local.domain.serverfqdn }}/ks/getvaultpass.py -O /tmp/getvaultpass.py +install -m744 -o root -g root /tmp/getvaultpass.py /var/lib/{{ ansible_local.domain.domainfull}}/bin/getvaultpass.py rm -f /tmp/getvaultpass.py # Installo lo script per l'avvio di ansible-pull da root -wget -q http://{{ serverfqdn }}/ks/ansible-pull.sh -O /tmp/ansible-pull.sh -install -m744 -o root -g root /tmp/ansible-pull.sh /var/lib/{{ domainfull }}/bin/ansible-pull.sh +wget -q http://{{ ansible_local.domain.serverfqdn }}/ks/ansible-pull.sh -O /tmp/ansible-pull.sh +install -m744 -o root -g root /tmp/ansible-pull.sh /var/lib/{{ ansible_local.domain.domainfull }}/bin/ansible-pull.sh rm -f /tmp/ansible-pull.sh # Installo il cronjob -wget -q http://{{ serverfqdn }}/ks/ansible-pull-crontab -O /tmp/ansible-pull-crontab +wget -q http://{{ ansible_local.domain.serverfqdn }}/ks/ansible-pull-crontab -O /tmp/ansible-pull-crontab install -m644 -o root -g root /tmp/ansible-pull-crontab /etc/cron.d/ansible-pull rm -f /tmp/ansible-pull-crontab # Installo il logrotate -wget -q http://{{ serverfqdn }}/ks/ansible-pull-logrotate -O /tmp/ansible-pull-logrotate +wget -q http://{{ ansible_local.domain.serverfqdn }}/ks/ansible-pull-logrotate -O /tmp/ansible-pull-logrotate install -m644 -o root -g root /tmp/ansible-pull-logrotate /etc/logrotate.d/ansible rm -f /tmp/ansible-pull-logrotate diff --git a/roles/kickstart/templates/profiles/client-trusty.cfg b/roles/kickstart/templates/profiles/client-trusty.cfg index bd7a4a3..4d2b401 100644 --- a/roles/kickstart/templates/profiles/client-trusty.cfg +++ b/roles/kickstart/templates/profiles/client-trusty.cfg @@ -20,7 +20,7 @@ text install #Use Web installation #url --url http://archive.ubuntu.com/ubuntu -url --url http://{{ mirrorpath }}archive.ubuntu.com/ubuntu +url --url http://{{ ubuntumirrorpath }}archive.ubuntu.com/ubuntu #System bootloader configuration bootloader --location=mbr #Clear the Master Boot Record @@ -61,4 +61,4 @@ sshpass #Post installation commands %post #the target filesystem in nochroot environment is in /target -\curl -sSL http://{{ serverfqdn }}/ks/post-ks.sh | bash >/root/post-ks.log 2>&1 +\curl -sSL http://{{ ansible_local.domain.serverfqdn }}/ks/post-ks.sh | bash >/root/post-ks.log 2>&1 diff --git a/roles/kickstart/templates/profiles/docenti-trusty.cfg b/roles/kickstart/templates/profiles/docenti-trusty.cfg index bd37263..b3fad56 100644 --- a/roles/kickstart/templates/profiles/docenti-trusty.cfg +++ b/roles/kickstart/templates/profiles/docenti-trusty.cfg @@ -20,7 +20,7 @@ text install #Use Web installation #url --url http://archive.ubuntu.com/ubuntu -url --url http://{{ mirrorpath }}archive.ubuntu.com/ubuntu +url --url http://{{ ubuntumirrorpath }}archive.ubuntu.com/ubuntu #System bootloader configuration bootloader --location=mbr #Clear the Master Boot Record @@ -52,6 +52,6 @@ openssh-server #Post installation commands %post --nochroot #the target filesystem in nochroot environment is in /target -TARGETHOSTNAME=$(wget -qO- http://{{ serverfqdn }}:3000/whatsmyhostname) +TARGETHOSTNAME=$(wget -qO- http://{{ ansible_local.domain.serverfqdn }}:3000/whatsmyhostname) echo $TARGETHOSTNAME > /target/etc/hostname sed -i "s/kickseed/$TARGETHOSTNAME/g" /target/etc/hosts diff --git a/roles/kickstart/templates/profiles/ubuntu-trusty.cfg b/roles/kickstart/templates/profiles/ubuntu-trusty.cfg index ab264a9..e6422ad 100644 --- a/roles/kickstart/templates/profiles/ubuntu-trusty.cfg +++ b/roles/kickstart/templates/profiles/ubuntu-trusty.cfg @@ -20,7 +20,7 @@ text install #Use Web installation #url --url http://archive.ubuntu.com/ubuntu -url --url http://archive.ubuntu.com/ubuntu +url --url http://{{ ubuntumirrorpath }}archive.ubuntu.com/ubuntu #System bootloader configuration bootloader --location=mbr #Clear the Master Boot Record @@ -47,6 +47,6 @@ openssh-server #Post installation commands %post --nochroot #the target filesystem in nochroot environment is in /target -TARGETHOSTNAME=$(wget -qO- http://{{ serverfqdn }}:3000/whatsmyhostname) +TARGETHOSTNAME=$(wget -qO- http://{{ ansible_local.domain.serverfqdn }}:3000/whatsmyhostname) echo $TARGETHOSTNAME > /target/etc/hostname sed -i "s/kickseed/$TARGETHOSTNAME/g" /target/etc/hosts diff --git a/roles/nethcfg/tasks/reconfig_nic.yml b/roles/nethcfg/tasks/reconfig_nic.yml index fc8294a..0b08b91 100644 --- a/roles/nethcfg/tasks/reconfig_nic.yml +++ b/roles/nethcfg/tasks/reconfig_nic.yml @@ -3,7 +3,7 @@ sudo: yes - name: Configurazione scheda di rete interna - shell: /sbin/e-smith/db networks setprop eth1 role green ipaddr {{ serverip }} netmask {{ servernetmask }} + shell: /sbin/e-smith/db networks setprop eth1 role green ipaddr {{ ansible_local.domain.serverip }} netmask {{ ansible_local.domain.servernetmask }} sudo: yes - name: Attivo configurazioni di rete @@ -11,7 +11,7 @@ sudo: yes - name: Configurazione rete trusted - shell: /sbin/e-smith/db networks set {{ servernet }} network Description "Local LAN" Mask {{ servernetmask }} + shell: /sbin/e-smith/db networks set {{ ansible_local.domain.servernet }} network Description "Local LAN" Mask {{ ansible_local.domain.servernetmask }} sudo: yes - name: Modifico configurazioni diff --git a/roles/nethcfg/tasks/reconfig_srv.yml b/roles/nethcfg/tasks/reconfig_srv.yml index 5fbacba..c9f066d 100644 --- a/roles/nethcfg/tasks/reconfig_srv.yml +++ b/roles/nethcfg/tasks/reconfig_srv.yml @@ -1,14 +1,14 @@ --- - name: Configurazione organizzazione - shell: /sbin/e-smith/db configuration setprop OrganizationContact City "{{ org_city }}" Company "{{ org_company }}" CountryCode {{ org_countrycode }} Department "{{ org_department }}" PhoneNumber "{{ org_phone }}" Street "{{ org_street }}" + shell: /sbin/e-smith/db configuration setprop OrganizationContact City "{{ ansible_local.domain.org_city }}" Company "{{ ansible_local.domain.org_company }}" CountryCode {{ ansible_local.domain.org_countrycode }} Department "{{ ansible_local.domain.org_department }}" PhoneNumber "{{ ansible_local.domain.org_phone }}" Street "{{ ansible_local.domain.org_street }}" sudo: yes - name: Configurazione nome server - shell: /sbin/e-smith/db configuration set SystemName {{ server }} + shell: /sbin/e-smith/db configuration set SystemName {{ ansible_local.domain.server }} sudo: yes - name: Configurazione nome dominio - shell: /sbin/e-smith/db configuration set DomainName {{ domainfull }} + shell: /sbin/e-smith/db configuration set DomainName {{ ansible_local.domain.domainfull }} sudo: yes - name: Attivazione cambiamenti hostname @@ -24,7 +24,7 @@ sudo: yes - name: Configurazione servizio DHCP - shell: /sbin/e-smith/db dhcp set eth1 range DhcpRangeStart {{ dhcprange_start }} DhcpRangeEnd {{ dhcprange_end }} status enabled + shell: /sbin/e-smith/db dhcp set eth1 range DhcpRangeStart {{ ansible_local.domain.dhcprange_start }} DhcpRangeEnd {{ ansible_local.domain.dhcprange_end }} status enabled sudo: yes - name: Attivazione configurazione DHCP @@ -32,7 +32,7 @@ sudo: yes - name: Configurazione servizio DNS - shell: /sbin/e-smith/db configuration setprop dns role resolver NameServers "{{ extdnsserver1 }},{{ extdnsserver2 }}" + shell: /sbin/e-smith/db configuration setprop dns role resolver NameServers "{{ ansible_local.domain.extdnsserver1 }},{{ ansible_local.domain.extdnsserver2 }}" sudo: yes register: cfg_dns @@ -50,7 +50,7 @@ sudo: yes - name: Configurazione SMB - shell: /sbin/e-smith/db configuration setprop smb RoamingProfiles yes ServerRole PDC Workgroup "{{ domainshort }}" status enabled + shell: /sbin/e-smith/db configuration setprop smb RoamingProfiles yes ServerRole PDC Workgroup "{{ ansible_local.domain.domainshort }}" status enabled sudo: yes - name: Attivo configurazione SMB diff --git a/roles/pxe/templates/pxelinux.cfg/default b/roles/pxe/templates/pxelinux.cfg/default index 2ae35d9..1fa64ef 100644 --- a/roles/pxe/templates/pxelinux.cfg/default +++ b/roles/pxe/templates/pxelinux.cfg/default @@ -9,13 +9,13 @@ LABEL client MENU LABEL Installa nuova macchina CLIENT LINUX /ubuntu/14.04/amd64/linux INITRD /ubuntu/14.04/amd64/initrd.gz - APPEND vga=normal ks=http://{{ serverfqdn }}/ks/profiles/client-trusty.cfg -- quiet + APPEND vga=normal ks=http://{{ ansible_local.domain.serverfqdn }}/ks/profiles/client-trusty.cfg -- quiet LABEL docenti MENU LABEL Installa nuova macchina DOCENTI LINUX /ubuntu/14.04/amd64/linux INITRD /ubuntu/14.04/amd64/initrd.gz - APPEND vga=normal ks=http://{{ serverfqdn }}/ks/profiles/docenti-trusty.cfg -- quiet + APPEND vga=normal ks=http://{{ ansible_local.domain.serverfqdn }}/ks/profiles/docenti-trusty.cfg -- quiet MENU SEPARATOR diff --git a/setup.yml b/setup.yml index dd37b8e..ef8fe44 100644 --- a/setup.yml +++ b/setup.yml @@ -1,8 +1,6 @@ --- - hosts: server - vars_files: - - domain.yml roles: - setup - nethcfg