Рубрики
openwrt

openwrt / ansible

scripts bash

cat  hosts.txt.ssh
------------------
192.168.1.1
192.168.1.2
192.168.1.3
------------------

cat resolv.conf
----------------
nameserver 192.168.1.1
----------------

#Копируем настройки  DNS
#scp resolv.conf
for i in `cat hosts.txt.ssh`; do scp resolv.conf ${i}:/etc/resolv.conf; done

#Устанавливаем python for ansible
for i in `cat hosts.txt.ssh`; do ssh $i opkg update ; done
for i in `cat hosts.txt.ssh`; do ssh $i opkg install python3-light python3-multiprocessing python3-distutils openssh-sftp-server python3-logging; done


#Ставим snmpd
for i in `cat hosts.txt.ssh`; do ssh $i opkg install  snmpd; done


#MAC
# parse MAC
for i in `cat hosts.txt | tail -n 39 | grep -v "#"`; do ssh $i ip a | grep ether | awk '{print $2}' && echo ; done
# parse MAC print host
for i in `cat hosts.txt | tail -n 39 | grep -v "#"`; do ssh $i uci get  system.@system[0].hostname && ip a | grep ether | awk '{print $2}' && echo ; done
##parse mac
for i in `cat hosts.txt | tail -n 39 | grep -v "#"`; do ssh $i fdddd="`uci get  system.@system[0].hostname`" && echo $fdddd  && ip a | grep ether | awk '{print $2}' && echo ; done
# parse mod 
# awk '{cmd="YOUCOMMAND" $1; system(cmd)}'
# cmd="uci get  system.@system[0].hostname"
#for i in `cat hosts.txt | tail -n 39 | grep -v "#"`; do ssh $i  ip a | grep ether | awk '{cmd="uci get  system.@system[0].hostname" print $2; system(cmd)}' && echo ; done


#scp file batman
for i in `cat hosts.txt | tail -n 39 | grep -v "#"`; do scp bat-hosts root@$i:/etc/bat-hosts; done


# generation ip 
for i in `seq 1 36`; do echo 192.168.1.${i} ; done 

Настройка сетевого имени openwrt:

# change hostname openwrt #
uci set system.@system[0].hostname=openwrt-20
uci commit system
echo newhostname > /proc/sys/kernel/hostname
reboot


Openwrt /etc/config/snmpd

config agent
        option agentaddress 'UDP:161,UDP6:161'

config agentx
        option agentxsocket '/var/run/agentx.sock'

config com2sec 'public'
        option secname 'ro'
        option source 'default'
        option community 'vasian'

config com2sec 'private'
        option secname 'rw'
        option source 'localhost'
        option community 'private'

config com2sec6 'public6'
        option secname 'ro'
        option source 'default'
        option community 'public'

config com2sec6 'private6'
        option secname 'rw'
        option source 'localhost'
        option community 'private'

config group 'public_v1'
        option group 'public'
        option version 'v1'
        option secname 'ro'

config group 'public_v2c'
        option group 'public'
        option version 'v2c'
        option secname 'ro'

config group 'public_usm'
        option group 'public'
        option version 'usm'
        option secname 'ro'

config group 'private_v1'
        option group 'private'
        option version 'v1'
        option secname 'rw'

config group 'private_v2c'
        option group 'private'
        option version 'v2c'
        option secname 'rw'

config group 'private_usm'
        option group 'private'
        option version 'usm'
        option secname 'rw'

config view 'all'
        option viewname 'all'
        option type 'included'
        option oid '.1'

config access 'public_access'
        option group 'public'
        option context 'none'
        option version 'any'
        option level 'noauth'
        option prefix 'exact'
        option read 'all'
        option write 'none'
        option notify 'none'

config access 'private_access'
        option group 'private'
        option context 'none'
        option version 'any'
        option level 'noauth'
        option prefix 'exact'
        option read 'all'
        option write 'all'
        option notify 'all'

config system
        option sysLocation 'office'
        option sysContact 'bofh@example.com'

config exec
        option name 'filedescriptors'
        option prog '/bin/cat'
        option args '/proc/sys/fs/file-nr'

config engineid
        option engineidtype '3'
        option engineidnic 'eth0'

config snmpd 'general'
        option enabled '1'

Debian /etc/snmp/snmpd.conf

sysServices    72
master  agentx
agentaddress  udp:161
view   systemonly  included   .1.3.6.1.2.1.1
view   systemonly  included   .1.3.6.1.2.1.25.1
rocommunity  vasian 192.168.0.0/16
createUser snmpreadonly SHA "SecUREDpass" AES "StRongPASS"
rouser snmpreadonly

_test_ansible.yml

---
- name: My TEST Playbook
  hosts: all
    #  become: yes
  
  tasks:
  - name: Ping test
    ping:    
...

copy-file-bat-hosts-to-server.yaml

---
- hosts: all
  #become: yes
  #gather_facts: false
  vars:
       destin_file_cli: /etc/bat-hosts
       source_file_cli: ./bat-hosts
 
  tasks:
  - name: Copy file bat-hosts to Servers
    copy: src={{ source_file_cli }} dest={{ destin_file_cli }} mode=0664 owner=root group=root backup=yes 
...

copy-file-snmpd-to-server.yaml

---
- hosts: all
  #  become: yes
  gather_facts: false
  vars:
       destin_file: /etc/config/snmpd
       source_file: ./snmpd.txt
 
  tasks:
  - name: Copy file snmpd to Servers
    copy: src={{ source_file }} dest={{ destin_file }} mode=0664 owner=root group=root backup=yes 
  
  - name: restart snmpd
    shell: /etc/init.d/snmpd restart
...

rm-copy-file-resolv-to-server.yaml

---
- hosts: all
  #  become: yes
  gather_facts: false
  vars:
       destin_file: /etc/resolv.conf
       source_file: ./resolv.conf
 
  tasks:
  - name: remove file resolv.conf
    file: 
      path: /etc/resolv.conf
      state: absent

  - name: Copy file resolv.conf  to Servers
    copy: src={{ source_file }} dest={{ destin_file }} mode=0664 owner=root group=root backup=yes 

...