From 8f3b1f124d8e36e65635427f4ec7ed95aa454441 Mon Sep 17 00:00:00 2001 From: Sergey Bubnov Date: Wed, 7 Nov 2018 13:22:14 +0400 Subject: [PATCH] just for test --- roles/common/tasks/configure_nics.yml | 2 +- roles/common/tasks/main.yml | 5 - roles/common/tasks/main.yml.orig | 144 ++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 roles/common/tasks/main.yml.orig diff --git a/roles/common/tasks/configure_nics.yml b/roles/common/tasks/configure_nics.yml index 248da44..9c3936d 100644 --- a/roles/common/tasks/configure_nics.yml +++ b/roles/common/tasks/configure_nics.yml @@ -22,7 +22,7 @@ when: nic.value.search is defined - name: "{{nic.key}} | set IP addresses (async)" - shell: egrep -q "^{{item|ipaddr('address')}}/{{item|ipaddr('prefix')}}$" /etc/net/ifaces/"{{nic.key}}"/ipv4address || { alterator-cmdline -d /net-eth action add_iface_address name "{{nic.key}}" addip "{{item|ipaddr('address')}}" addmask "{{item|ipaddr('prefix')}}" disabled no ipv 4 configuration "static" ipv_enabled "#t"; echo addr_changed; } + shell: egrep -q "^{{item|ipaddr('address')}}/{{item|ipaddr('prefix')}}$" /etc/net/ifaces/"{{nic.key}}"/ipv4address || { alterator-cmdline -d /net-eth action add_iface_address name "{{nic.key}}" addip "{{item|ipaddr('address')}}" addmask "{{item|ipaddr('prefix')}}" ipv 4 configuration "static" ipv_enabled "#t"; echo addr_changed; } register: result changed_when: result.stdout is defined and '"addr_changed" in result.stdout' notify: restart network diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 4af8330..121d977 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -90,11 +90,6 @@ async: 100 poll: 0 -- name: restart network service - service: - name: network - state: restarted - - name: update .tmp/ssh_config after NICs reconfiguration include_role: name="inventory" diff --git a/roles/common/tasks/main.yml.orig b/roles/common/tasks/main.yml.orig new file mode 100644 index 0000000..3dd1aaa --- /dev/null +++ b/roles/common/tasks/main.yml.orig @@ -0,0 +1,144 @@ +--- +- set_fact: ansible_pkg_mgr=apt_rpm +- set_fact: node="{{inventory_hostname_short}}" +- set_fact: node="{{stack.nodes[inventory_hostname_short]}}" + +- name: wait nodes for connection + wait_for_connection: + delay: 3 + timeout: 60 + +- name: disable apt-cache in tmpfs + block: + - lineinfile: + path: /etc/rc.d/rc.local + regexp: '^/etc/rc\.d/scripts/apt-cache-on-tmp.*' + state: absent + backrefs: yes + - file: + path: /etc/apt/apt.conf.d/tmp.cache.conf + state: absent + +- name: purge apt.sources + shell: find /etc/apt/sources.list.d/ -name '*.list' -delete + changed_when: false + +- name: set apt sources + template: + src: "apt.list.j2" + dest: "/etc/apt/sources.list.d/{{item}}.list" + with_items: "{{env.apt.sources}}" + +- name: update packages list + shell: apt-get update + +- name: include additional apt repos from tasks + template: + src: "apt.list.tasks.j2" + dest: "/etc/apt/sources.list.d/tasks.list" + when: stack.apt_sources_from_tasks is defined + +- name: allow apt downgrade packages + template: + src: "downgrade.j2" + dest: "/etc/apt/preferences.d/downgrade" + when: node.arch == 'e2k' + +- name: install common packages + apt_rpm: + pkg: ntpdate,curl + state: installed + update_cache: yes + +- name: install Alterator`s modules + apt_rpm: + pkg: alterator,alterator-net-eth +# pkg: alterator,alterator-alternatives,alterator-audit,alterator-bind,alterator-datetime,alterator-dhcp,alterator-groups,alterator-mirror,alterator-mkimage,alterator-net-bond,alterator-net-bridge,alterator-net-domain,alterator-net-eth,alterator-net-functions,alterator-net-iptables,alterator-net-routing,alterator-net-vlan,alterator-packages,alterator-services,alterator-sshd,alterator-sysconfig,alterator-users,alterator-vsftpd,alterator-xinetd + state: installed + +# FIX: don't know how to switch from dhcp to static via alterator +# just remove this line from options file for now +- name: remove options for eth0 + lineinfile: + dest: /etc/net/ifaces/eth0/options + regexp: '^BOOTPROTO=dhcp.*' + backrefs: yes + state: absent + +- name: disable IPv6 + sysctl: name={{ item }} value=1 state=present + with_items: + - net.ipv6.conf.all.disable_ipv6 + - net.ipv6.conf.default.disable_ipv6 + - net.ipv6.conf.lo.disable_ipv6 + +- name: blacklisting IPv6 module + template: + src: ipv6-disable.conf.j2 + dest: /etc/modprobe.d/options-local.conf + +- name: configure NICs + include_tasks: configure_nics.yml + with_dict: "{{node.net}}" + loop_control: + loop_var: nic + # when: node.net is defined + +- name: apply NICs config + command: alterator-cmdline /net-eth action write commit "#t" + changed_when: false + async: 100 + poll: 0 + +- name: update .tmp/ssh_config after NICs reconfiguration + include_role: name="inventory" + +- name: wait for the host`s NIC to come back + wait_for_connection: + delay: 2 + timeout: 300 + +# TODO: need to make it idempotent! +- name: set hostname + shell: '[[ $(hostname -s) == "{{inventory_hostname_short}}" ]] || { alterator-cmdline -d /net-eth action write computer_name "{{inventory_hostname_short}}" commit "#t"; echo changed; }' + register: result + notify: restart network + changed_when: '"changed" in result.stdout' + +- name: set domainname + # shell: '[[ $(domainname) == "{{stack.domain}}" ]] || { alterator-cmdline -d /net-domain action write domain "{{stack.domain}}" domain_type "dns" commit "#t"; echo changed; }' + shell: '[[ $(domainname) == "{{stack.domain}}" ]] || { domainname "{{stack.domain}}"; echo changed; }' + register: result + notify: restart network + changed_when: '"changed" in result.stdout' + +- name: delete .bash_logout + file: + path: /root/.bash_logout + state: absent + +- meta: flush_handlers + +- setup: + +- name: register users keys + template: + dest: /etc/openssh/authorized_keys/root + src: authorized_keys + owner: root + group: root + mode: 0644 + +- name: fetch ssh host keys + fetch: + src: /etc/openssh/ssh_host_rsa_key.pub + dest: ".tmp/{{ inventory_hostname_short }}.ssh_host_rsa_key.pub" + +- name: mount nfs shares + mount: + src: "{{item.from}}" + path: "{{item.to}}" + fstype: "{{item.fstype}}" + state: mounted + with_items: "{{node.mounts}}" + when: node.mounts is defined