What is the best way to manage machines that aren't defined as hosts?

13 views
Skip to first unread message

Kurt Robinson

unread,
Aug 16, 2019, 12:15:33 AM8/16/19
to Ansible Project
I intend to Ansible to run deployment configuration on a number of Dell ESXi hosts in VMware using VMware and OpenManage modules.

In my past ansible training, my playbooks have always run from hosts that I have defined in an inventory file. The machines I wish to configure don't have ansible installed so they will be managed from the localhost node.

My question is, what is the best practice in running configuration tasks on these machines that aren't actual hosts within ansible?

Currently, I am thinking of creating a csv file which will contain the host information, then loop through each host and run my tasks to run on each host using read_csv.



pseudo:

- name: Read csv and send to task
  csv_read: csvname.csv
  task:
    - taskname 
  passvar:
    - csv.hostname

____

- name : Run task
  loop: name in csv.hostnames
    do: something



To me this seems like I am under-engineering the solution a bit. Is there a better way I can do this?

Would I be able to add the list of hosts that I want to configure to an inventory file, then reference a group for which I will run my configurations on?

E.g.

inventory

[management]
10.0.0.1
10.0.0.2

[database]
10.1.0.1
10.1.0.2

__

- name: Set DNS on hosts
  vmware_module:
    hostname: '{{ management group }}'
    dns: 1.2.3.4



Thanks for taking the time.


Zolvaring

unread,
Aug 16, 2019, 1:35:09 AM8/16/19
to ansible...@googlegroups.com
I'm not sure I understand fully, but none of the hosts you are configuring need Ansible to be installed for you make changes remotely. Instead of defining your hosts in a CSV, define your hosts as part of Ansible inventory and your tasks will loop through them naturally. You can also group hosts as you had mentioned, and run task or assign vars to specific groups, just as you had in your example. To execute a play only on remote esxi servers one way is:

- name: configure esxi hosts
  hosts: esxi-hosts
  roles:
     - your roles here

If I run this play and have 5 esxi hosts in my inventory group, then this will run all roles or tasks each time for each of those 5 servers in parallel

Making use of group_vars files and host_vars files can change the play vars based on the group.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2c702252-eae3-461e-842f-989e80d88537%40googlegroups.com.

Zolvaring

unread,
Aug 16, 2019, 1:36:31 AM8/16/19
to Ansible Project

Zolvaring

unread,
Aug 16, 2019, 1:42:35 AM8/16/19
to Ansible Project
Seeing that you may want to loop through actual guests, I would still define them as Ansible inventory hosts if you know them ahead of time, and if you need to run tasks from a different host by invoking VMware module then try:

- name: do a thing to a guest
vmware_module:
regular_module_args
delegate_to: localhost (or somewhere else)

The end result will still naturally loop your inventory but will run from whichever host you delegate the commands to.

Mike Eggleston

unread,
Aug 16, 2019, 11:46:21 AM8/16/19
to ansible...@googlegroups.com
Create a local, temporary file of the new hosts and environment variable ANSIBLE_INVENTORY?

Mike
Reply all
Reply to author
Forward
0 new messages