]> git.apps.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
Setup static IPs for baremetal machines running ubuntu.
authorAndrew Schoen <aschoen@redhat.com>
Tue, 14 Apr 2015 14:09:06 +0000 (09:09 -0500)
committerAndrew Schoen <aschoen@redhat.com>
Thu, 16 Apr 2015 21:31:33 +0000 (16:31 -0500)
Signed-off-by: Andrew Schoen <aschoen@redhat.com>
roles/testnode/files/scripts/static-ip.sh [new file with mode: 0644]
roles/testnode/tasks/setup-ubuntu.yml
roles/testnode/tasks/static_ip.yml [new file with mode: 0644]

diff --git a/roles/testnode/files/scripts/static-ip.sh b/roles/testnode/files/scripts/static-ip.sh
new file mode 100644 (file)
index 0000000..c4cfa41
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/bash
+## {{ ansible_managed }}
+
+dontrun=$(grep -ic inet\ static /etc/network/interfaces)
+if [ $dontrun -eq 0 ]
+then
+cidr=$(ip addr show dev eth0 | grep -iw inet | awk '{print $2}')
+ip=$(echo $cidr | cut -d'/' -f1)
+miracheck=$(uname -n | grep -ic mira)
+armcheck=$(uname -m | grep -ic arm)
+netmask=$(ipcalc $cidr | grep -i netmask | awk '{print $2}')
+gateway=$(route -n | grep ^0.0 | awk '{print $2}')
+broadcast=$(ipcalc $cidr | grep -i broad | awk '{print $2}')
+octet1=$(echo $ip | cut -d'.' -f1)
+octet2=$(echo $ip | cut -d'.' -f2)
+octet3=$(echo $ip | cut -d'.' -f3)
+octet4=$(echo $ip | cut -d'.' -f4)
+octet3=$(($octet3 + 13))
+if [ $armcheck -gt 0 ]
+then
+dev=eth1
+else
+dev=eth2
+fi
+if [ $miracheck -gt 0 ]
+then
+sed -i "s/iface eth0 inet dhcp/\
+iface eth0 inet static\n\
+    address $ip\n\
+    netmask $netmask\n\
+    gateway $gateway\n\
+    broadcast $broadcast\n\
+\n\
+/g" /etc/network/interfaces
+else
+typicacheck=$(uname -n | grep -ic typica)
+if [ $typicacheck -gt 0 ]
+then
+sed -i "s/iface eth0 inet dhcp/\
+iface eth0 inet static\n\
+    address $ip\n\
+    netmask $netmask\n\
+    gateway $gateway\n\
+    broadcast $broadcast\n\
+    up route add -net 10.99.118.0\/24 gw 172.20.133.1 dev eth0\n\
+    up route add -net 10.214.128.0\/20 gw 172.20.133.1 dev eth0\n\
+    up route add -net 10.214.0.0\/20 gw 172.20.133.1 dev eth0\n\
+\n\
+/g" /etc/network/interfaces
+else
+sed -i "s/iface eth0 inet dhcp/\
+iface eth0 inet static\n\
+    address $ip\n\
+    netmask $netmask\n\
+    gateway $gateway\n\
+    broadcast $broadcast\n\
+\n\
+auto $dev\n\
+iface $dev inet static\n\
+    address $octet1.$octet2.$octet3.$octet4\n\
+    netmask $netmask\
+/g" /etc/network/interfaces
+fi
+fi
+fi
+touch /static-ip-setup
index 8a4f7e5f1397ff80223a0b2765d4259449561106..4b64db49e17612349449c1761c0697525f152cee 100644 (file)
 - include: nfs.yml
   tags:
     - nfs
+
+# is not run on virtual machines
+- include: static_ip.yml
+  when: "'vps' not in group_names"
diff --git a/roles/testnode/tasks/static_ip.yml b/roles/testnode/tasks/static_ip.yml
new file mode 100644 (file)
index 0000000..2876055
--- /dev/null
@@ -0,0 +1,12 @@
+---
+- name: Set up static IP in /etc/hosts.
+  lineinfile:
+    dest: /etc/hosts
+    line: "{{ ansible_default_ipv4['address'] }} {{ ansible_fqdn }} {{ ansible_hostname }}"
+    regexp: "^127.0.1.1"
+    backrefs: yes
+    state: present
+
+# this script was ported directly from chef.
+- name: Set up static IP and 10gig interface.
+  script: scripts/static-ip.sh creates=/static-ip-setup