0

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?

2
  • dont know ansible, but can you use dictionaries? Key value pairs might solve your problem Commented Dec 10, 2015 at 18:05
  • Can you clarify your question? It is unclear what you are asking Commented Dec 10, 2015 at 18:13

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Haha that's funny I just figured this out as well. Here is the syntax used in the hosts file user='["test2", "test3"]' Then in the play user: "name={{ item }} state=absent remove=yes" with_items: "{{ user }}" That is what I used.
What is the class example you are referring to?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.