Ansible:仅当上一个任务成功并创建了输出时才触发该任务

Ansible:仅当上一个任务成功并创建了输出时才触发该任务,ansible,yaml,devops,Ansible,Yaml,Devops,我正在azure中使用ansible部署VM,并使用在下一个任务中创建的公共ip。但是创建公共ip所花费的时间太长,因此在执行后续任务时,它会失败。创建ip的时间也不同,它不是固定的。我想介绍一些逻辑,其中下一个任务将仅在创建ip时运行 - name: Deploy Master Node azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm10 admin_username: ch

我正在azure中使用ansible部署VM,并使用在下一个任务中创建的公共ip。但是创建公共ip所花费的时间太长,因此在执行后续任务时,它会失败。创建ip的时间也不同,它不是固定的。我想介绍一些逻辑,其中下一个任务将仅在创建ip时运行

- name: Deploy Master Node
  azure_rm_virtualmachine:
    resource_group: myResourceGroup
    name: testvm10
    admin_username: chouseknecht
    admin_password: <your password here>
    image:
      offer: CentOS-CI
      publisher: OpenLogic
      sku: '7-CI'
      version: latest
-名称:部署主节点
azure\u rm\u虚拟机:
资源组:myResourceGroup
名称:testvm10
管理员\用户名:chouseknecht
管理员密码:
图片:
报价:CentOS CI
发布者:OpenLogic
sku:'7-CI'
版本:最新

有人能帮我吗。。!非常感谢。

我认为
等待
模块是一个糟糕的选择,因为虽然它可以测试端口可用性,但它通常会给您误报,因为端口在服务实际准备接受连接之前就已打开

幸运的是,该模块正是为您描述的情况而设计的:它将等待Ansible成功连接到您的目标

这通常要求您使用Ansible资源清册注册Azure VM(例如,使用
add_host
模块)。我不使用Azure,但如果我使用OpenStack,我可能会这样写:

- hosts: localhost
  gather_facts: false
  tasks:
    # This is the task that creates the vm, much like your existing task
    - os_server:
        name: larstest
        cloud: kaizen-lars
        image: 669142a3-fbda-4a83-bce8-e09371660e2c
        key_name: default
        flavor: m1.small
        security_groups: allow_ssh
        nics:
          - net-name: test_net0
        auto_ip: true
      register: myserver

    # Now we take the public ip from the previous task and use it
    # to create a new inventory entry for a host named "myserver".
    - add_host:
        name: myserver
        ansible_host: "{{ myserver.openstack.accessIPv4 }}"
        ansible_user: centos

# Now we wait for the host to finished booting. We need gather_facts: false here
# because otherwise Ansible will attempt to run the `setup` module on the target,
# which will fail if the host isn't ready yet.
- hosts: myserver
  gather_facts: false
  tasks:
    - wait_for_connection:
        delay: 10

# We could add additional tasks to the previous play, but we can also start
# new play with implicit fact gathering.
- hosts: myserver
  tasks:
    - ...other tasks here...

这看起来是Hi@Zeitounator的完美用例,Nope wait_for模块将只等待上一个任务完成。但我的情况是任务正在完成,但IP是在很长一段时间后创建的。你有没有把@Zeitounator链接的文档弄红?有一个例子,它在特定接口上等待特定端口