Is it possible to use tags to assign (ansible) server role with cloud-init?

Hi Everyone,

I am quite new to ManageIQ automation and I am trying to automate provisioning of VM’s with cloud-init and Ansible.

  • I have created a new tags category like ansibleroles and added tags based on roles like apache, jboss etc. User has to select appropriate tags for the role they want VM to have.

  • Now I want to use these selected tags by user in cloud init script . Similar to what we do for assigning hostname, password , fqdn
    expire: false
    list: "root:<%= MiqPassword.decrypt(evm[:root_password]) %>\n"
    hostname: <%= (evm[:hostname]) %>
    fqdn: <%= evm[:hostname] %>

    Here I want to use tag variable values using something like <%= (evm[:ansibleroles]) %>
    But getting empty values

I have also added following method in postprovision

tags = prov.get_tags
$evm.log(“info”,“Tags: #{tags.inspect}”)
ansibleroles = tags[:ansibleroles]
$evm.log(“info”, “Mapping custom spec based on Category RoleofVM < #{ansibleroles} > chosen in the dialog”)

EVM logs here throws the correct tags selected by user but I am not able to use this in cloud-init script.

Most likely either I am missing something or may be this approach is not right.

Can anyone point me to the right direction ?


@gmccullough can you review this question from @ipc and forward to a SME if necessary.

The evm[<key>] resolution you are using comes from the options hash for the provision task. To reference the tag value you will need to set the text you want into the options.

If you add the following line into the method logic you will be able to resolve the value but this will need to be performed in a pre_provisioning method so it is available during the the cloud-init resolution.

  prov.set_option(:ansibleroles, ansibleroles)

cc @bdunne @syncrou

Thanks @gmccullough and @jprause , this worked and I am able to use them in cloud-init

Thanks for the support