User Tools

Site Tools


сервис_ansible

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
сервис_ansible [2024/11/15 12:19]
val [Пример 1]
сервис_ansible [2025/03/15 16:44] (current)
val [Использование модулей]
Line 1: Line 1:
 ====== Сервис Ansible ====== ====== Сервис Ansible ======
 +
 +  * [[https://​www.goncharov.xyz/​it/​make-cm-not-bash-ru.html|Вот рассмотрим банальный пример. выбрать все файлы в текущей директории и скопировать в другое место]]
  
   * Управление инфраструктурой на примере [[https://​ru.wikipedia.org/​wiki/​Ansible|Аnsible - wikipedia]]   * Управление инфраструктурой на примере [[https://​ru.wikipedia.org/​wiki/​Ansible|Аnsible - wikipedia]]
Line 60: 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 106: 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 183: Line 182:
           - containerd.io           - containerd.io
           - docker-compose-plugin           - docker-compose-plugin
 +          - docker-buildx-plugin
         state: present ​         state: present ​
         update_cache:​ true         update_cache:​ true
Line 190: Line 190:
  
 <​code>​ <​code>​
-server# ansible-playbook provision_docker.yml+server# ansible-playbook provision_docker.yml --syntax-check 
 + 
 +server# ansible-playbook provision_docker.yml ​
  
 server# ansible-playbook provision_docker.yml --extra-vars "​variable_host=nodes"​ server# ansible-playbook provision_docker.yml --extra-vars "​variable_host=nodes"​
  
-server# ansible-playbook provision_docker.yml --extra-vars ​"​variable_host=localhost"​+server# ansible-playbook provision_docker.yml -"​variable_host=localhost"​
  
 server# ansible-playbook provision_docker.yml -i inv_file.ini server# ansible-playbook provision_docker.yml -i inv_file.ini
Line 311: 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 324: Line 328:
 </​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 
 + 
 +server# ansible-playbook inst_http.yml -i gate,
 </​code><​code>​ </​code><​code>​
 # cat iax.conf.j2 # cat iax.conf.j2
Line 341: Line 350:
 disallow=all disallow=all
 allow=alaw allow=alaw
 +
 +{#
 +Comment
 +#}
  
 {% for Y in YS %} {% for Y in YS %}
Line 442: Line 455:
   hosts: addnodes   hosts: addnodes
 #  hosts: kubes #  hosts: kubes
-#  hosts: ​all+#  hosts: ​"{{ variable_host | default('​addnodes'​) }}"
   roles:   roles:
     - node     - node
Line 497: Line 510:
 </​code><​code>​ </​code><​code>​
 search corp{{ X }}.un search corp{{ X }}.un
 +{% if variable_host is defined %}
 +nameserver 192.168.{{ X }}.10
 +{% else %}
 nameserver 192.168.{{ X }}.1 nameserver 192.168.{{ X }}.1
 nameserver 192.168.{{ X }}.2 nameserver 192.168.{{ X }}.2
-#nameserver 192.168.{{ X }}.10+{% endif %}
 </​code><​code>​ </​code><​code>​
 # cat node/​templates/​interfaces.j2 # cat node/​templates/​interfaces.j2
Line 510: Line 526:
         address {{ ansible_eth0.ipv4.address }}         address {{ ansible_eth0.ipv4.address }}
         netmask 255.255.255.0         netmask 255.255.255.0
 +{% if variable_host is defined %}
 +        gateway 192.168.{{ X }}.1
 +{% else %}
         gateway 192.168.{{ X }}.254         gateway 192.168.{{ X }}.254
-#        gateway 192.168.{{ X }}.1+{% endif %}
 </​code><​code>​ </​code><​code>​
 # ansible-playbook -f 5 nodes.yml # ansible-playbook -f 5 nodes.yml
Line 521: Line 540:
   ИЛИ   ИЛИ
  
-(venv1) server# ansible-playbook -f 5 /​root/​conf/​ansible/​roles/​nodes.yml -i /​root/​kubespray/​inventory/​mycluster/​hosts.yaml #​--limit=kube4+(venv1) server# ansible-playbook -f 5 /​root/​conf/​ansible/​roles/​nodes.yml -i /​root/​kubespray/​inventory/​mycluster/​hosts.yaml ​-e "​variable_host=all name_prefix=kube" ​#​--limit=kube4
 </​code>​ </​code>​
  
 ==== Роль OpenVPN сервера ==== ==== Роль OpenVPN сервера ====
 +
 +  * [[Пакет OpenVPN]]
 +
 <​code>​ <​code>​
 server:~# mkdir openvpn1 && cd openvpn1 server:~# mkdir openvpn1 && cd openvpn1
Line 615: Line 637:
   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 642: Line 663:
 </​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"​
сервис_ansible.1731662361.txt.gz · Last modified: 2024/11/15 12:19 by val