【问题标题】:Ansible - actions BEFORE gathering factsAnsible - 收集事实之前的行动
【发布时间】:2015-09-12 07:15:18
【问题描述】:

有谁知道如何做某事(例如等待受管节点的端口/启动)收集事实之前?我知道我可以关闭收集事实

gather_facts: no

and THEN 等待端口,但是如果我需要事实同时还需要等到节点启动怎么办?

【问题讨论】:

    标签: ansible ansible-facts


    【解决方案1】:

    收集事实相当于运行setup module。您可以通过运行它来手动收集事实。它没有记录,但只需添加这样的任务:

    - name: Gathering facts
      setup:
    

    结合剧本级别的gather_facts: no,只有在执行上述任务时才会获取事实。

    都在示例剧本中:

    - hosts: all
      gather_facts: no
      tasks:
    
        - name: Some task executed before gathering facts
          # whatever task you want to run
    
        - name: Gathering facts
          setup:
    

    【讨论】:

      【解决方案2】:

      这样的事情应该可以工作:

      - hosts: my_hosts
        gather_facts: no
      
        tasks:
            - name: wait for SSH to respond on all hosts
              local_action: wait_for port=22
      
            - name: gather facts
              setup:
      
            - continue with my tasks...
      

      wait_for 将在您的 ansible 主机上本地执行,等待服务器在端口 22 上响应,然后 setup 模块将执行事实收集,之后您可以做任何其他需要做的事情。

      【讨论】:

        【解决方案3】:

        我试图弄清楚如何从 ec2 配置主机,等待 ssh 启动,然后针对它运行我的剧本。这与您的用例基本相同。我最终得到以下结果:

        - 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----
        

        我认为 ansible 术语是我在剧本中有两个剧本,每个剧本都在不同的主机组(localhost 和 appServer 组)上运行

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-01-12
          • 1970-01-01
          • 2017-01-03
          • 1970-01-01
          • 2023-04-02
          • 1970-01-01
          • 2018-01-16
          • 2018-09-15
          相关资源
          最近更新 更多