我有一个角色名称
system_check
。系统启动后,我需要等到这个角色成功。
有没有办法反复运行这个角色,直到成功?
Q: “有没有办法让一个角色一直演到成功?”
答:不可能。模块include_role说
忽略一些关键字,比如 until 和 retries.
相反,使用 ansible-runner。例如使用 Runner 作为独立的命令行工具并测试artifacts(rc,status,stdout)。
#!/bin/bash
rcfile=private1/artifacts/ID01/rc
statusfile=private1/artifacts/ID01/status
ansible-runner -p test.yml -i ID01 run private1
rc=$(cat $rcfile)
echo "rc: $rc"
until [ "0" == "$rc" ]; do
ansible-runner -p test.yml -i ID01 run private1
rc=$(cat $rcfile)
echo "rc: $rc"
done
$ tree private1
private1
├── artifacts
├── daemon.log
├── env
│ ├── envvars
│ ├── extravars
│ ├── passwords
│ ├── settings
│ └── ssh_key
├── inventory
│ └── hosts
└── project
├── roles
│ └── testrole
│ ├── defaults
│ │ └── main.yml
│ ├── handlers
│ │ └── main.yml
│ ├── meta
│ │ └── main.yml
│ ├── README.md
│ ├── tasks
│ │ └── main.yml
│ ├── tests
│ │ ├── inventory
│ │ └── test.yml
│ └── vars
│ └── main.yml
└── test.yml