有没有办法运行一个角色,直到它演戏成功?

Is there a way to running a role until it succeeds in a play?

我有一个角色名称system_check。 系统启动后,我需要等到这个角色成功。 有没有办法让这个角色反复运行直到成功?

Q: "Is there a way to running a role until it succeeds in a play?"

答:不可能。模块 include_role

Ignores some keywords, like until and retries.

而是使用 ansible-runner. For example Use Runner as a standalone command line tool and test 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