Reload Ansible's dynamic inventory

前端 未结 5 1160
-上瘾入骨i
-上瘾入骨i 2020-12-05 06:43

I\'m using Ansible to setup EC2 instances and deploy an app. There\'s a hosts script which gathers tags related servers and groups info. I\'d like to run these actions as a

相关标签:
5条回答
  • 2020-12-05 06:48

    You can also edit the ec2.ini file and set the option:

    cache_max_age = 0

    to prevent the need for reload by making sure that nothing is cached in the first place.

    0 讨论(0)
  • 2020-12-05 06:49

    I found the meta: refresh_inventory to be insufficient.
    I had to add an explicit call to ec2.py --refresh-cache first.

    - name: refresh inventory
      hosts: localhost
      connection: local
      gather_facts: False
      tasks:
        - name: Refresh EC2 cache
          command: /etc/ansible/ec2.py --refresh-cache
        - name: Refresh in-memory EC2 cache
          meta: refresh_inventory
    
    0 讨论(0)
  • 2020-12-05 06:52

    Take a look at add_host.

    It does add a host (and alternatively a group) to the ansible-playbook in-memory inventory

    0 讨论(0)
  • 2020-12-05 06:53

    With Ansible 2.0+, you can refresh your inventory mid-play by running the task:

    - meta: refresh_inventory
    
    0 讨论(0)
  • 2020-12-05 07:00

    Ansible currently doesn't support this. If you look at the source code of the ansible or ansible-playbook commands you'll see that the inventory is loaded first and then the inventory object is passed to the ansible command that runs the specified task or playbook. Moving the inventory processing so that it happens within the task/playbook handlers would probably be a pretty major undertaking for a number of reasons.

    Your best bet when doing something like this is to simply break your playbook into two and wrap their calls in a shell script that you only have to invoke once.

    0 讨论(0)
提交回复
热议问题