对照表
linux命令
apt-get
替换国内源
echo "" > /etc/apt/sources.list
echo "deb https://mirrors.aliyun.com/debian stable main contrib non-free">>/etc/apt/sources.list
echo "deb https://mirrors.aliyun.com/debian stable-updates main contrib non-free">>/etc/apt/sources.list
apt-get clean
apt-get update
apt-get upgrade -y
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/blockinfile_module.html#ansible-collections-ansible-builtin-blockinfile-module
- name: 添加镜像源
ansible.builtin.blockinfile:
path: /etc/apt/sources.list
append_newline: true
prepend_newline: true
block: |
deb https://mirrors.aliyun.com/debian stable main contrib non-free
deb https://mirrors.aliyun.com/debian stable-updates main contrib non-free
- name: 更新镜像源
ansible.builtin.command: apt-get update
等价于
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_repository_module.html#ansible-collections-ansible-builtin-apt-repository-module
- name: 添加阿里云镜像源1
ansible.builtin.apt_repository:
install_python_apt: false
repo: deb https://mirrors.aliyun.com/debian stable main contrib non-free
state: present
update_cache: false
- name: 添加阿里云镜像源2
ansible.builtin.apt_repository:
install_python_apt: false
repo: deb https://mirrors.aliyun.com/debian stable-updates main contrib non-free
备注
不使用ansible.builtin.apt_repository的原因: 依赖python3-apt包,缺失时会自动安装,但此时访问的是官方源(例如docker启动的ubuntu容器),很慢。 如果是线上服务器,本身配好国内源镜像可以使用方案二
docker
build
$ docker build -t localhost/python/3.12:latest -f Dockerfile-3.12 /home/user/images/python
- name: Build Python 3.12 image
community.docker.docker_image_build:
name: localhost/python/3.12:latest
path: /home/user/images/python
dockerfile: Dockerfile-3.12
push
$ docker push registry.example.com:5000/repo/image:latest
- name: Push an image
community.docker.docker_image_push:
name: registry.example.com:5000/repo/image
tag: latest
supervisorctl
ansible使用supervisor模块的前提是supervisord已启动
start
> supervisorctl start my_app
- name: Manage the state of program to be in started state
community.general.supervisorctl:
name: my_app
state: started
restart
重启所有进程
> supervisorctl restart all
- name: Restart all programs and program groups
community.general.supervisorctl:
name: all
state: restarted