- Регистрация
- 04.03.23
- Сообщения
- 344
- Реакции
- 60
Код:
{% set id = 'rbta_ldap_custom_gp_host_change_repo_to_local' %}
{% set my_host = salt['grains.get']("nodename") %}
{% set gpo = salt['pillar.get']('aldpro-hosts:'+ my_host + ':' + id) %}
{% if gpo %}
{% set nsd = namespace(delete_old_repo = 0) %}
{% set sourcelist = '/etc/apt/sources.list' %}
{% set use_local_repo = 'false' %}
{% set nsc = namespace(count = 0) %}
{% set nsa = namespace(add_repo_without_clean = 'false') %}
{% for args in gpo %}
{% if args.get('use_local_repo') is defined %}
{% set use_local_repo = args.get('use_local_repo') %}
{% endif %}
{% if use_local_repo|lower == 'true' %}
{% set repository_check = '"deb \[trusted=yes\] ' + args.get('repository_name') + '"' %}
{% else %}
{% set repository_check = '"deb ' + args.get('repository_name') + '"' %}
{% endif %}
{% set repo_exist = salt['cmd.shell']('grep -c ' + repository_check + ' ' + sourcelist) %}
{% if repo_exist|float == 0 %}
{% set nsd.delete_old_repo = 1 %}
{% endif %}
{% set nsc.count = nsc.count + 1 %}
{% if args.get('add_repo_without_clean') is defined %}
{% set nsa.add_repo_without_clean = args.get('add_repo_without_clean') %}
{% endif %}
{% endfor %}
{% set lines_in_source = salt['cmd.shell']('wc -l ' + sourcelist + ' | cut -b 1-2') %}
{% if nsd.delete_old_repo == 1 or lines_in_source|float != nsc.count%}
{% if nsa.add_repo_without_clean|lower == 'false' %}
remove_lines_in_sources:
cmd.run:
- name: '> {{ sourcelist }}'
- runas: root
{% endif %}
{% for args in gpo %}
{% if args.get('use_local_repo') is defined %}
{% set use_local_repo = args.get('use_local_repo') %}
{% endif %}
{% if use_local_repo|lower == 'true' %}
{% set repository_name = 'deb [trusted=yes] ' + args.get('repository_name') %}
{% else %}
{% set repository_name = 'deb ' + args.get('repository_name') %}
{% endif %}
add_{{ repository_name }}_to_{{ sourcelist }}:
file.replace:
- name: '{{ sourcelist }}'
- pattern: '{{ repository_name }}'
- repl: '{{ repository_name }}'
- append_if_not_found: True
{% endfor %}
update_pkg:
pkg.uptodate:
- dist_upgrade: True
- refresh: True
- kwargs:
- -o "Dpkg::options::=--force-confold"
- -o "Dpkg::options::=--force-confdef"
- --allow-downgrades
- -f
- -u
{% endif %}
{% endif %}
Тип параметра - составной
Основные атрибуты:
Использовать локальные репозитории true означает добавление [trusted=yes] для не подписанного репозитория
Последнее редактирование: