1
+ # 02_add_users.py
2
+ #
3
+ # This file will create users and assign them to the appropriate groups. It should be run after
4
+ # 01_add_groups.py as it will query ISE for the created groups and their corresponding ids.
5
+ # You should not need to modify this file as it will dynamically read all of the users and groups
6
+ # from groupsandusers.yaml.
7
+ #
8
+ # The group name to group id matching and variable assignment is kind of irritating, but.....
9
+ #
10
+ # Actually it's more that ISE requires a group id instead of a group name when creating a user.
11
+
12
+ import yaml # import pyyaml package
13
+
14
+ # open the yaml file and load it into data
15
+ with open ('credentials.yaml' ) as f :
16
+ data = yaml .safe_load (f )
17
+
18
+ # open the groupsandusers.yaml file and load it into groups
19
+ with open ('groupsandusers.yaml' ) as g :
20
+ groups = yaml .safe_load (g )
21
+
22
+ # Pull in the Cisco ISE SDK
23
+ from ciscoisesdk import IdentityServicesEngineAPI
24
+
25
+ # define our API
26
+ api = IdentityServicesEngineAPI (username = data ['ise_username' ],
27
+ password = data ['ise_password' ],
28
+ uses_api_gateway = True ,
29
+ base_url = 'https://' + data ['ise_hostname' ],
30
+ version = data ['ise_version' ],
31
+ verify = data ['ise_verify' ])
32
+
33
+ # We're going to iterate through the list of users and create them using the information in credentials.yaml,
34
+ # but first we need to get the group id for each group
35
+ for groupname in groups ['userlist' ]:
36
+ groupinfo = api .identity_groups .get_identity_group_by_name (name = groupname ['groups' ]).response
37
+ groupid = groupinfo .IdentityGroup .id
38
+ api .internal_user .create_internal_user (name = groupname ['name' ],
39
+ first_name = groupname ['firstname' ],
40
+ last_name = groupname ['lastname' ],
41
+ description = groupname ['description' ],
42
+ password = groups ['default_password' ],
43
+ password_idstore = "Internal Users" )
44
+ print ("Creating user:" , groupname ['name' ])
0 commit comments