How to find secondary IP addresses from a knife search - ruby

I was going through chef, and when this part came where search queries can be put inside the recipe files, I am facing a problem when I try to fetch the secondary IP addresses of a node.
When I try to get the primary IP address, I can get is as
>> knife node show web1 -a ipaddress
web1:
ipaddress: 10.0.2.15
But when I try to fetch the secondary IP address, I could see that the key itself is the secondary IP.
>> knife node show web1 -a network.interfaces.eth0.addresses
web1:
network.interfaces.eth0.addresses:
08:00:27:6E:B1:DB:
family: lladdr
192.168.10.43:
broadcast: 192.168.10.255
family: inet
netmask: 255.255.255.0
prefixlen: 24
scope: Global
fe80::a00:27ff:fe6e:b1db:
family: inet6
prefixlen: 64
scope: Link
tags:
How can I extract the secondary IP field directly in this case, which comes as 192.168.10.43 ?

knife search and knife node show display the full object data and are not intended for scripting. We offer knife exec for simple Ruby scripts or libraries like chef-api or PyChef for more complex things.

Related

Ansible Playbook for Cisco Router Configuration with Unique Arguments

I've used Ansible for 'show' commands to validate configurations, but have not used it to configure.
Want to use Ansible to configure 60+ routers with IP SLA and Track. Then tying the Track to a static ip route statement.
The IP SLA and Track configuration will be the same on all routers. So I can write it in the playbook and apply it to all.
However, each router's ip route statement has a unique variable, as the next hop IP address is different on each router, such as:
RTR1:
ip route 0.0.0.0 0.0.0.0 x.x.x.x
RTR2:
ip route 0.0.0.0 0.0.0.0 y.y.y.y
My understanding is that the 'next hop' variable can be handled with Jinja2 in Ansible. I've never used it. Can someone please point me in the right direction in terms of using Jinja with above variables or if there's a better/alternate method.
I'm running Ansible version 2.9.22, Ubuntu 18.0.4
The output of configuration on each router is shown below - which also reflects the exact configuration input.
track 8 ip sla 1 reachability
ip sla 1
icmp-echo 10.1.13.2 source-ip 10.0.12.1
ip sla schedule 1 life forever start-time now
ip route 0.0.0.0 0.0.0.0 x.x.x.x track 8
ip route 0.0.0.0 0.0.0.0 x.x.x.x 10
Please note that the 'x.x.x.x', which is the next hop variable will be different on each router.

force Static IP on VM creation

I have an ansible script that connects to my Vcenter and builds out a VM. This works great assuming the network it will be built on has DHCP enabled. I am building mostly Centos 7 VM's on a network that does not have DHCP enabled meaning static IP's. The VM gets built, but then I am stuck logging into each VM manually and assigning the IP.
How can I tell CentOS to use a specific IP?
I am familiar with kickstart, but not sure how to trigger the install to pickup a ks file. (I know I can create a custom ISO, but I dont want to create a custom ISO for each VM I built.)
I have tried using the following flags on ansible VMware_guest module, but no luck.
Any Suggestions??
vmware_guest:
network:
type: static
ip: 192.168.1.5
mask: 255.255.255.0
gateway: 192.168.1.1
Please try using netmask instead of mask.
vmware_guest:
network:
name: "{{ network_name }}"
type: static
ip: 192.168.1.5
netmask: 255.255.255.0
gateway: 192.168.1.1

How external interfaces work in OMNETPP/INET?

I have been trying in the past few days to build and run a very simple network to no avail (most of the network I try to build is borrowed from extServer example). No matter my configuration in terms of IP addresses, routes etc. I cannot seem to make it work.
I have seen many people struggling with it, but have not found any solutions posted anywhere. The readme file in the Emulation folder of INET is more confusing than helpful.
Hence, I would like your help in making the following simple network work and, hopefully, even make it (the post) a tutorial for others as well.
The network I want to build (could not be simpler):
External Server <----> [ext0] ROUTER [ppp0] <----> [ppp0] Standard Host
My setup:
Software:
OMNET++ 4.6 with PCAP enabled.
INET Integration head (includes several features that I like).
OS:
Xubuntu in VirtualBox as a guest which hosts OMNET++. The reason for using Virtualbox is that my Host Win 7 machine refuses to run any external interface example with the error "cSocketRTScheduler: couldn't set socketopt for raw socket.". I modified the source a bit and used WSAGetLastError function, which resolved the issue as "The requested address is not valid in its context.".
Back to VirtualBox :)
Xubuntu has one network interface set to Host-only networking with IP address 10.0.0.1 and netmask 255.255.255.0 .
Standard Host Setup in omnetpp.ini:
**.server.numTcpApps = 1
**.server.tcpApp[*].typename = "TCPSinkApp"
**.server.tcpApp[*].localAddress = "172.0.1.111"
**.server.tcpApp[*].localPort = 10021
The standard host is using the same server.mrt from extServer example.
The router.mrt is as follows:
ifconfig:
# interface 1 to server
name: ppp0
inet_addr: 172.0.1.100
Mask: 255.255.255.0
MTU: 1500
POINTTOPOINT MULTICAST
# interface 2 to external server (real network interface)
name: ext0
inet_addr: 10.0.0.2
Mask: 255.255.255.0
MTU: 1500
POINTTOPOINT MULTICAST
ifconfigend.
route:
#Destination Gateway Genmask Flags Metric Iface
172.0.1.111 172.0.1.100 255.255.255.255 H 0 ppp0
10.0.0.1 10.0.0.2 255.255.255.255 H 0 ext0
0.0.0.0 * 0.0.0.0 G 0 ext0
routeend.
Any ideas on how to make this network work are really welcome as, should it work, I want to expand it later. Also, I would greatly appreciate it if any suggestions are in step-by-step style.
Thank you in advance.

Running multiple instances of Cassandra on a single machine by aliasing the IP address?

Looking at the configuration for Cassandra I can see that nodes are distinguished by IP address in /apache-cassandra-2.0.3/conf/cassandra.yaml.
cluster_name: ‘VirtualBox Cluster’
initial_token: 0
seed_provider:
- seeds: "192.168.56.2"
listen_address: 192.168.56.2
rpc_address: 0.0.0.0
endpoint_snitch: RackInferringSnitch
I'd like to run multiple nodes on my MacOSX Mavericks machine (without spinning up virtual machines)
My question is: Will it work for me to distinguish multiple nodes by creating an IP address alias using ifconfig? eg
sudo ifconfig en0 alias 192.168.0.101 255.255.255.0
The short answer is that yes this is possible, but you may prefer using CCM as a management tool for testing without VM's. In the repo readme it shows aliasing various IP's to 127.0.0.1 for setting up multiple cass instances on one machine.
- ccm works on localhost only for now. So if you want to create more than one
node clusters the simplest way is to use multiple loopback aliases. On
modern linux distribution you will probably have nothing to do, but
on mac os x, you would have to create such aliases with
sudo ifconfig lo0 alias 127.0.0.2 up
sudo ifconfig lo0 alias 127.0.0.3 up
https://github.com/pcmanus/ccm

get iscsi ip from initiator name

In Linux how can I get iscsi target IP if I know the initiatorname either programmatically or by reading /sys filesystem. That is Without using iscsiadm or reading /etc/iscsi/node/* links.
Thanks
Found it:
initiator ip: /sys/class/scsi_host/$host/device/iscsi_host/${host}/ipaddress
target ip: /sys/class/scsi_host/$host/device/session${s}/connection*/iscsi_connection/connection*/address
where $host the scsi host name

Resources