This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
сервис_ansible [2024/11/29 13:39] val [Использование шаблонов] |
сервис_ansible [2025/06/02 13:30] (current) val [Провижининг IP телефонов] |
||
---|---|---|---|
Line 62: | Line 62: | ||
[sws] | [sws] | ||
- | switch[1:3] ansible_ssh_user=root ansible_ssh_pass=cisco #ansible_network_os=ios | + | switch[1:3] ansible_ssh_user=root ansible_ssh_pass=cisco ansible_network_os=ios |
[nodes] | [nodes] | ||
Line 108: | Line 108: | ||
node1# ansible all -m ping | node1# ansible all -m ping | ||
node1# ansible all -m ping -i inv_file.ini | node1# ansible all -m ping -i inv_file.ini | ||
- | node1# ansible all -m ping -i node2:2222, -e "ansible_python_interpreter=/usr/bin/python3" | + | node1# ansible all -m ping -i node2:2222, |
node1# ansible corpX -m command -a 'uname -a' | node1# ansible corpX -m command -a 'uname -a' | ||
- | kube1# ansible kubes -a 'sed -i"" -e "/swap/s/^/#/" /etc/fstab' | ||
- | kube1# ansible kubes -a 'swapoff -a' | ||
- | ИЛИ | ||
(venv1) server# ansible all -a 'sed -i"" -e "/swap/s/^/#/" /etc/fstab' -i /root/kubespray/inventory/mycluster/hosts.yaml #--limit=kube4,kube5 | (venv1) server# ansible all -a 'sed -i"" -e "/swap/s/^/#/" /etc/fstab' -i /root/kubespray/inventory/mycluster/hosts.yaml #--limit=kube4,kube5 | ||
(venv1) server# ansible all -a 'swapoff -a' -i /root/kubespray/inventory/mycluster/hosts.yaml #--limit=kube4 | (venv1) server# ansible all -a 'swapoff -a' -i /root/kubespray/inventory/mycluster/hosts.yaml #--limit=kube4 | ||
Line 316: | Line 313: | ||
<code> | <code> | ||
node1# ansible -m setup corpX | node1# ansible -m setup corpX | ||
+ | |||
+ | server# ansible all -m setup -i gate, | ||
node1# ansible -m setup corpX | grep ansible_fqdn | node1# ansible -m setup corpX | grep ansible_fqdn | ||
Line 325: | Line 324: | ||
<h1> | <h1> | ||
Hello from {{ ansible_fqdn }} | Hello from {{ ansible_fqdn }} | ||
- | {# | ||
- | Comment | ||
- | #} | ||
</h1> | </h1> | ||
</body> | </body> | ||
</html> | </html> | ||
</code><code> | </code><code> | ||
- | node1# cat inst_apache.yml | + | node1# cat inst_http.yml |
</code><code> | </code><code> | ||
- hosts: corpX | - hosts: corpX | ||
+ | #- hosts: all | ||
+ | |||
tasks: | tasks: | ||
- | - name: Installs apache web server | + | - name: Install or remove web server |
apt: pkg=apache2 state=present update_cache=true | apt: pkg=apache2 state=present update_cache=true | ||
+ | # apt: pkg=nginx state=absent update_cache=true | ||
- name: Create index.html file | - name: Create index.html file | ||
template: src=index.html.j2 dest=/var/www/html/index.html | template: src=index.html.j2 dest=/var/www/html/index.html | ||
</code><code> | </code><code> | ||
- | node1# ansible-playbook inst_apache.yml | + | node1# ansible-playbook inst_http.yml |
- | </code><code> | + | |
+ | server# ansible-playbook inst_http.yml -i gate, | ||
+ | </code> | ||
+ | |||
+ | ==== Asterisk IAX конфигурация ==== | ||
+ | |||
+ | <code> | ||
# cat iax.conf.j2 | # cat iax.conf.j2 | ||
</code><code> | </code><code> | ||
Line 349: | Line 354: | ||
disallow=all | disallow=all | ||
allow=alaw | allow=alaw | ||
+ | |||
+ | {# | ||
+ | Comment | ||
+ | #} | ||
{% for Y in YS %} | {% for Y in YS %} | ||
Line 377: | Line 386: | ||
</code><code> | </code><code> | ||
# ansible-playbook ast_iax_corps.yml --extra-vars '{"X":"{{ ansible_eth0.ipv4.address.split(\".\")[3] }}","YS":[1,2,3,4,5,6,7,8,9,10,11,12,13]}' | # ansible-playbook ast_iax_corps.yml --extra-vars '{"X":"{{ ansible_eth0.ipv4.address.split(\".\")[3] }}","YS":[1,2,3,4,5,6,7,8,9,10,11,12,13]}' | ||
+ | </code> | ||
+ | |||
+ | ==== Провижининг IP телефонов ==== | ||
+ | <code> | ||
+ | ~/phone-prov# cat inventory.yml | ||
+ | </code><code> | ||
+ | all: | ||
+ | vars: | ||
+ | phones: | ||
+ | - [ '403', 'tpassword403', 'server.corp13.un', '000E08C190C2', 'spa' ] | ||
+ | - [ '404', 'tpassword404', 'server.corp13.un', 'BCC34221709A', 'kx-hdv' ] | ||
+ | </code><code> | ||
+ | ~/phone-prov# cat kx-hdv.j2 | ||
+ | </code><code> | ||
+ | # Panasonic SIP Phone Standard Format File # | ||
+ | |||
+ | ## SIP Settings | ||
+ | PHONE_NUMBER_1="{{ pn }}" | ||
+ | SIP_AUTHID_1="{{ pn }}" | ||
+ | SIP_PASS_1="{{ secret }}" | ||
+ | SIP_PRXY_ADDR_1="{{ sipproxy }}" | ||
+ | SIP_RGSTR_ADDR_1="{{ sipproxy }}" | ||
+ | DIAL_PLAN_1="*xx|[1-4]xx|0xxxxx|8xxxxxxxxxx" | ||
+ | </code><code> | ||
+ | ~/phone-prov# cat spa.j2 | ||
+ | </code><code> | ||
+ | <flat-profile> | ||
+ | <Proxy_1_>{{ sipproxy }}</Proxy_1_> | ||
+ | <User_ID_1_>{{ pn }}</User_ID_1_> | ||
+ | <Password_1_>{{ secret }}</Password_1_> | ||
+ | <Dial_Plan_1_>( xxx | 8xxxxxxxxxx | 0xxxxx | *xx )</Dial_Plan_1_> | ||
+ | </flat-profile> | ||
+ | </code><code> | ||
+ | ~/phone-prov# cat phone-prov.yml | ||
+ | </code><code> | ||
+ | - hosts: localhost | ||
+ | tasks: | ||
+ | - name: debug | ||
+ | debug: | ||
+ | msg: "{{ item.0 }} ... {{ item.4 }}" | ||
+ | loop: "{{ phones }}" | ||
+ | - name: Create phone conf | ||
+ | template: | ||
+ | src: "{{ model }}.j2" | ||
+ | dest: "/var/www/html/{{ model }}-{{ mac }}.cfg" | ||
+ | vars: | ||
+ | pn: "{{ item.0 }}" | ||
+ | secret: "{{ item.1 }}" | ||
+ | sipproxy: "{{ item.2 }}" | ||
+ | mac: "{{ item.3 }}" | ||
+ | model: "{{ item.4 }}" | ||
+ | loop: "{{ phones }}" | ||
+ | </code><code> | ||
+ | ~/phone-prov# ansible-playbook phone-prov.yml -i inventory.yml | ||
</code> | </code> | ||
===== Использование handlers ===== | ===== Использование handlers ===== | ||
- | ==== Пример 1 ==== | + | ==== Пример 4 ==== |
* [[Сервис HTTP#Использование домашних каталогов]] | * [[Сервис HTTP#Использование домашних каталогов]] | ||
Line 404: | Line 467: | ||
</code> | </code> | ||
- | ==== Пример 2 ==== | + | ==== Пример 5 ==== |
+ | |||
+ | * [[Управление ПО в Linux#Список desktop приложений]] | ||
<code> | <code> | ||
Line 414: | Line 479: | ||
UserParameter=listinstalledsoft,ls /usr/share/applications | awk -F '.desktop' ' { print $1}' - | UserParameter=listinstalledsoft,ls /usr/share/applications | awk -F '.desktop' ' { print $1}' - | ||
</code><code> | </code><code> | ||
- | node1# cat za.yml | + | server# cat za.yml |
</code><code> | </code><code> | ||
- hosts: lin_ws | - hosts: lin_ws | ||
Line 451: | Line 516: | ||
# hosts: kubes | # hosts: kubes | ||
# hosts: "{{ variable_host | default('addnodes') }}" | # hosts: "{{ variable_host | default('addnodes') }}" | ||
- | "{{ variable_host | default('addnodes') }}" | ||
roles: | roles: | ||
- node | - node | ||
Line 522: | Line 586: | ||
address {{ ansible_eth0.ipv4.address }} | address {{ ansible_eth0.ipv4.address }} | ||
netmask 255.255.255.0 | netmask 255.255.255.0 | ||
- | {% if variable_host == 'all' %} | + | {% if variable_host is defined %} |
gateway 192.168.{{ X }}.1 | gateway 192.168.{{ X }}.1 | ||
{% else %} | {% else %} | ||
Line 540: | Line 604: | ||
==== Роль OpenVPN сервера ==== | ==== Роль OpenVPN сервера ==== | ||
+ | |||
+ | * [[Пакет OpenVPN]] | ||
+ | |||
<code> | <code> | ||
server:~# mkdir openvpn1 && cd openvpn1 | server:~# mkdir openvpn1 && cd openvpn1 | ||
Line 630: | Line 697: | ||
vars: | vars: | ||
X: "{{ ansible_eth1.ipv4.address.split('.')[2] }}" | X: "{{ ansible_eth1.ipv4.address.split('.')[2] }}" | ||
- | ansible_python_interpreter: "/usr/bin/python3" | ||
ansible_ssh_user: vagrant | ansible_ssh_user: vagrant | ||
ansible_ssh_pass: strongpassword | ansible_ssh_pass: strongpassword | ||
Line 657: | Line 723: | ||
</code><code> | </code><code> | ||
server:~# wget https://val.bmstu.ru/unix/conf.git/conf/ansible/roles/openvpn1.tgz && tar -xvzf openvpn1.tgz && cd openvpn1 | server:~# wget https://val.bmstu.ru/unix/conf.git/conf/ansible/roles/openvpn1.tgz && tar -xvzf openvpn1.tgz && cd openvpn1 | ||
+ | |||
+ | server:~/openvpn1# ansible -m ping -i inventory.yaml all | ||
server:~/openvpn1# ansible-playbook openvpn1.yaml -i inventory.yaml -e "variable_host=test_nodes" | server:~/openvpn1# ansible-playbook openvpn1.yaml -i inventory.yaml -e "variable_host=test_nodes" |