updated apt state
This commit is contained in:
parent
25e7ca4917
commit
769dfd0917
24
states/apt/apt.py.j2
Executable file
24
states/apt/apt.py.j2
Executable file
@ -0,0 +1,24 @@
|
||||
{%- from "apt/map.jinja" import apt with context -%}
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
SCHEME = "{{ apt.proxy.scheme }}"
|
||||
HOSTNAME = "{{ apt.proxy.hostname }}"
|
||||
PORT = "{{ apt.proxy.port }}"
|
||||
|
||||
def main():
|
||||
regex = re.compile(f".*{HOSTNAME}.*")
|
||||
cmd = subprocess.Popen(f"avahi-resolve-host-name {HOSTNAME}",
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
result = cmd.stdout.read().decode().splitlines()
|
||||
if len(result) > 0:
|
||||
if regex.match(result[0]):
|
||||
return f"{SCHEME}://{HOSTNAME}:{PORT}"
|
||||
return "DIRECT"
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(main())
|
@ -1,6 +1,17 @@
|
||||
---
|
||||
apt:
|
||||
config: {}
|
||||
proxy:
|
||||
scheme: http
|
||||
hostname: apt.local
|
||||
port: 8000
|
||||
config:
|
||||
10proxy:
|
||||
content:
|
||||
- Acquire::http::ProxyAutoDetect "/usr/local/bin/apt-proxy-detect.py";
|
||||
- Acquire::https::Proxy "DIRECT";
|
||||
99unauth:
|
||||
content:
|
||||
- APT::Get::AllowUnauthenticated "true";
|
||||
|
||||
# apt:
|
||||
# config:
|
||||
|
@ -1,9 +1,22 @@
|
||||
---
|
||||
{%- from "apt/map.jinja" import apt with context %}
|
||||
apt-deps:
|
||||
pkg.installed:
|
||||
- pkgs:
|
||||
- avahi-daemon
|
||||
- avahi-utils
|
||||
|
||||
apt-proxy-detect:
|
||||
file.managed:
|
||||
- name: /usr/local/bin/apt-proxy-detect.py
|
||||
- source: salt://apt/apt.py.j2
|
||||
- template: jinja
|
||||
- mode: "0755"
|
||||
|
||||
{% for itemkey, itemvalue in apt.config.items() -%}
|
||||
apt-proxy-{{ itemkey }}:
|
||||
file.managed:
|
||||
- name: /etc/apt/apt.conf.d/{{ k }}
|
||||
- name: /etc/apt/apt.conf.d/{{ itemkey }}
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: "0644"
|
||||
|
Loading…
Reference in New Issue
Block a user