有没有办法让一个角色一直运行到成功?

问题描述 投票:0回答:1

我有一个角色名称

system_check
。系统启动后,我需要等到这个角色成功。

有没有办法反复运行这个角色,直到成功?

ansible repeat roles
1个回答
3
投票

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
© www.soinside.com 2019 - 2024. All rights reserved.