0

Im trying to write a logic (ansible playbook) where different roles are called based on the conditions.

Eg: AWS role should be in invoked if the condition matches for AWS, likewise for GCP, AZURE, vmware.

Tried to check through ansible_facts, no much information is available. Please help, which condition can I use.

Thanks

  • 4
    Hi blitz01, welcome to SO. Your question is too vague for anyone to possibly answer. How would you decide if a role is to be included, setting ansible aside for a second? Ansible is only an automation tool for carrying out your choices, so what are your choices? – mdaniel Jan 29 '21 at 20:52

1 Answers1

0

The cloud provider would be a property of the inventory and not the host itself.

Identification of the cloud provider can be done while the inventory is being built.

As such, during inventory build you can use additional variables/ groups in your hosts file to pass such information as shown in examples below

    [aws_hosts]
    host1
    host2
    [aws_hosts:vars]
    cloud_provider=aws

Then use the hostvars magic variable within the script to identify the cloud provider.

    hostvars[host1].cloud_provider

More information can be found here.

rohatgisanat
  • 708
  • 6
  • 15