Ansible - actions BEFORE gathering facts

前端 未结 3 984
旧巷少年郎
旧巷少年郎 2021-01-31 07:36

Does anyone know how to do something (like wait for port / boot of the managed node) BEFORE gathering facts? I know I can turn gathering facts off

gathe         


        
3条回答
  •  生来不讨喜
    2021-01-31 08:13

    I was trying to figure out how to provision a host from ec2, wait for ssh to come up, and then run my playbook against it. Which is basically the same use case as you have. I ended up with the following:

    - name: Provision App Server from Amazon
      hosts: localhost
      gather_facts: False
      tasks:  
        # ####  call ec2 provisioning tasks here  ####
        - name: Add new instance to host group
          add_host: hostname="{{item.private_ip}}" groupname="appServer"
          with_items: ec2.instances
    
    - name: Configure App Server
      hosts: appServer
      remote_user: ubuntu
      gather_facts: True
      tasks:  ----configuration tasks here----
    

    I think the ansible terminology is that I have two plays in a playbook, each operating on a different group of hosts (localhost, and the appServer group)

提交回复
热议问题