容器环境中安装salt-master salt-api

FROM centos:7
 
RUN echo -e "[salt]\nname=salt\nbaseurl=https://archive.repo.saltproject.io/yum/redhat/7/x86_64/3000/\nenabled=1\ngpgcheck=0\n" >/etc/yum.repos.d/salt.repo &&\
    curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &&\
    ls /etc/yum.repos.d/*.repo|xargs -I {} sed -i s/mirrorlist.centos.org/mirrors.aliyun.com/g {} &&\
    yum install salt-master salt-minion salt-api -y &&\
    echo "auto_accept: True" >>/etc/salt/master &&\
    useradd -M -s /sbin/nologin pcloud &&\
    echo "pcloud:Cmb@2018" | chpasswd
 
COPY api.conf /etc/salt/master.d/api.conf
COPY auth.conf /etc/salt/master.d/auth.conf
COPY eauth.conf /etc/salt/master.d/eauth.conf
COPY entrypoint.sh /
 
ENTRYPOINT ["/entrypoint.sh"]
tee entrypoint.sh <<EOF
#!/bin/bash
start(){
salt-master -d
salt-minion -d 
salt-api -d
}
start
exec "\$@"
EOF
tee api.conf  <<EOF
rest_cherrypy:
  host: 0.0.0.0
  port: 8000
  debug: False
  disable_ssl: True
  log.error_file: /var/log/salt/saltapi-err.log
EOF
tee auth.conf  <<EOF
external_auth:
  pam:
    pcloud:
      - .*
      - '@wheel'
      - '@runner'
      - '@jobs'
EOF
tee eauth.conf <<EOF
external_auth:
  pam:
    pcloud:
      - .*
      - '@wheel'
      - '@runner'
EOF

构建

chmod +x entrypoint.sh

docker build . -t 1209233066/salt:master-api

启动

docker run -d --name salt --hostname=salt -p8000:8000 -p4505:4505 -p4506:4506 -v /data:/data 1209233066/salt:master-api tail -f /dev/null
token=`curl -sk http://127.0.0.1:8000/login -H 'Accept: application/x-yaml' -d username='pcloud' -d password='Cmb@2018' -d eauth='pam'|awk '/token/{print $2}'`
curl -sk http://127.0.0.1:8000 -H "Accept: application/json" -H "X-Auth-Token: $token" -d client="local" -d tgt="salt" -d fun="test.ping"
posted @ 2023-10-19 18:14  mingtian是吧  阅读(45)  评论(0编辑  收藏  举报