对照表
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
git
git pull
tasks:
  - name: Git拉取代码(clone和pull)
    ansible.builtin.git:
      repo: 'git@gitee.com:luzhenxiong/paradox-playground.git'
      dest: '{{ base_path }}'
      # 如果目录不存在执行git clone
      clone: true
      # 检测revisions, 存在差异执行git pull
      update: true
      # 指定master分支
      version: master
    notify:
      - 收集静态资源
警告
command命令执行git pull的弊端: 总是显示changed。因为每次执行git pull返回 Already up to date. 这在ansible看来是属于存在变更。
关联远程仓库
git remote add origin https://paradox@git.xxxx.com.cn/scm/~paradox/proj.git
git stash
https://git-scm.com/docs/git-stash
todo
todo
submodule
https://git-scm.com/docs/gitsubmodules#_workflow_for_an_artificially_split_repo
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