# 安装依赖
$ ansible-galaxy install -r requirements.yml
# 安装 playbook
$ ansible-playbook -i hosts git.yml
$ ansibel all -m ping
$ ansible all -m setup
$ ansible all -a pwd
添加参数 when
作为分支条件
# 当在国内时,选择阿里云镜像
- name: add docker repo -> aliyun
shell: yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
when: ansible_date_time.tz_offset == "+0800"
args:
creates: /etc/yum.repos.d/docker-ce.repo
添加参数 ignore_errors: true
忽略错误
使用 register
来监听当前任务的执行情况,使用 when
设定条件
git,file 能够更好地满足幂等性
- 在使用相关 ansible 模块前请先确认是否满足 requirements