简体   繁体   中英

Is it possible to assign multiple variables to individual hosts in ansible?

Example.

[main] 192.168.1.1 users="test1, test2"

This example does not work since this type of var requires a key value. But is it possible to do this in anyway? And if so what is the correct syntax to use?

For a better look at what I want to do. I have hundreds of users that I need to remove off of hundreds of different servers. So I want to assign a list of users to each different host. Something like this.

host1 users={{ list }}

Or something like that?

Is this possible?

In python you can use dictionaries, which are essentially key-value pairs. They are optimized to fetch values based on keys, but not the other way around. So in your case, if you have a list of user data, and want to efficiently assign it to a user, you can set the key to the username, and the value to the list. It would look something like this

users = {"user1" = ["Bill", "42", "Bald"],
         "user2" = ["Sally", "25", "Red"]}

It might be more efficient to use classes, because you would be able to reference the different attributes, which are essentially things that identify an object of that class. So each user would have an attribute name , age , and hair , perhaps.

Classes are a huge topic, so it might be good to read the Python documentation for 2.7 or 3.5 , or just do a quick google search

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM