From 9f7b066ca62061c38e0f051cc80c5707da6a229e Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Sun, 4 Oct 2015 21:50:29 +0800 Subject: [PATCH] shouquanxiugai --- jperm/models.py | 45 ++++--- jperm/perm_api.py | 111 +++++++++++++++++ jperm/urls.py | 3 +- jperm/views.py | 56 ++++++++- jumpserver/api.py | 4 + jumpserver/models.py | 12 ++ jumpserver/urls.py | 1 + jumpserver/views.py | 3 + juser/models.py | 2 + playbook/user_perm.yaml | 17 +++ static/js/base.js | 8 +- templates/jperm/perm_edit.html | 2 +- .../{user_perm.html => perm_user_edit.html} | 68 +++++------ .../{perm_list.html => perm_user_list.html} | 57 +++------ templates/nav.html | 3 + templates/setting.html | 112 ++++++++++++++++++ tmp/147164c46a9611e5a797000c29f7d66e | 3 + tmp/14721dba6a9611e5a797000c29f7d66e | 17 +++ tmp/1d0e27de6a9611e5ae2e000c29f7d66e | 3 + tmp/1d0e993a6a9611e5ae2e000c29f7d66e | 17 +++ tmp/2e6324f46a9511e58276000c29f7d66e | 3 + tmp/2e63c0b26a9511e58276000c29f7d66e | 17 +++ tmp/39c5fac46a9511e585f9000c29f7d66e | 3 + tmp/39c69db26a9511e585f9000c29f7d66e | 17 +++ tmp/3ce93d2c6a9211e5a651000c29f7d66e | 4 + tmp/3ceb07b06a9211e5a651000c29f7d66e | 10 ++ tmp/48fd55966a9511e59d6b000c29f7d66e | 4 + tmp/48fdf7626a9511e59d6b000c29f7d66e | 17 +++ tmp/764e1d166a9311e5886c000c29f7d66e | 5 + tmp/765012a66a9311e5886c000c29f7d66e | 17 +++ tmp/aa4bd3526a9211e5a53f000c29f7d66e | 4 + tmp/aa4cbc546a9211e5a53f000c29f7d66e | 10 ++ tmp/bbd799fa6a9511e59e68000c29f7d66e | 3 + tmp/bbd931026a9511e59e68000c29f7d66e | 17 +++ tmp/c2774ea46a9511e5be00000c29f7d66e | 3 + tmp/c2780ae26a9511e5be00000c29f7d66e | 17 +++ tmp/c6a8384a6a8a11e5b929000c29f7d66e | 11 ++ tmp/d3e0469c6a8511e5ae99000c29f7d66e | 6 + tmp/f8b99a686a9411e5b0fb000c29f7d66e | 3 + tmp/f8bb07546a9411e5b0fb000c29f7d66e | 17 +++ 40 files changed, 627 insertions(+), 105 deletions(-) create mode 100644 jperm/perm_api.py create mode 100644 jumpserver/models.py create mode 100644 playbook/user_perm.yaml rename templates/jperm/{user_perm.html => perm_user_edit.html} (71%) rename templates/jperm/{perm_list.html => perm_user_list.html} (52%) create mode 100644 templates/setting.html create mode 100644 tmp/147164c46a9611e5a797000c29f7d66e create mode 100644 tmp/14721dba6a9611e5a797000c29f7d66e create mode 100644 tmp/1d0e27de6a9611e5ae2e000c29f7d66e create mode 100644 tmp/1d0e993a6a9611e5ae2e000c29f7d66e create mode 100644 tmp/2e6324f46a9511e58276000c29f7d66e create mode 100644 tmp/2e63c0b26a9511e58276000c29f7d66e create mode 100644 tmp/39c5fac46a9511e585f9000c29f7d66e create mode 100644 tmp/39c69db26a9511e585f9000c29f7d66e create mode 100644 tmp/3ce93d2c6a9211e5a651000c29f7d66e create mode 100644 tmp/3ceb07b06a9211e5a651000c29f7d66e create mode 100644 tmp/48fd55966a9511e59d6b000c29f7d66e create mode 100644 tmp/48fdf7626a9511e59d6b000c29f7d66e create mode 100644 tmp/764e1d166a9311e5886c000c29f7d66e create mode 100644 tmp/765012a66a9311e5886c000c29f7d66e create mode 100644 tmp/aa4bd3526a9211e5a53f000c29f7d66e create mode 100644 tmp/aa4cbc546a9211e5a53f000c29f7d66e create mode 100644 tmp/bbd799fa6a9511e59e68000c29f7d66e create mode 100644 tmp/bbd931026a9511e59e68000c29f7d66e create mode 100644 tmp/c2774ea46a9511e5be00000c29f7d66e create mode 100644 tmp/c2780ae26a9511e5be00000c29f7d66e create mode 100644 tmp/c6a8384a6a8a11e5b929000c29f7d66e create mode 100644 tmp/d3e0469c6a8511e5ae99000c29f7d66e create mode 100644 tmp/f8b99a686a9411e5b0fb000c29f7d66e create mode 100644 tmp/f8bb07546a9411e5b0fb000c29f7d66e diff --git a/jperm/models.py b/jperm/models.py index 167ae0485..336016f8f 100644 --- a/jperm/models.py +++ b/jperm/models.py @@ -5,22 +5,37 @@ from juser.models import User, UserGroup from jasset.models import Asset, AssetGroup -class UserPerm(models.Model): - user = models.ForeignKey(User) - asset = models.ForeignKey(Asset, null=True) - asset_group = models.ForeignKey(AssetGroup, null=True) +# class PermUserAsset(models.Model): +# user = models.ForeignKey(User) +# asset = models.ForeignKey(Asset) +# +# def __unicode__(self): +# return self.user.username +# +# +# class PermUserAssetGroup(models.Model): +# user = models.ForeignKey(User) +# asset_group = models.ForeignKey(AssetGroup) +# +# def __unicode__(self): +# return self.user.username +# +# +# class PermUserGroupAsset(models.Model): +# user_group = models.ForeignKey(UserGroup) +# asset = models.ForeignKey(Asset) +# +# def __unicode__(self): +# return self.user_group.name +# +# +# class PermUserGroupAssetGroup(models.Model): +# user_group = models.ForeignKey(UserGroup) +# asset_group = models.ForeignKey(AssetGroup) +# +# def __unicode__(self): +# return self.user_group.name - def __unicode__(self): - return self.user.name - - -class GroupPerm(models.Model): - user_group = models.ForeignKey(UserGroup) - asset = models.ForeignKey(Asset, null=True) - asset_group = models.ForeignKey(AssetGroup, null=True) - - def __unicode__(self): - return self.user.name # class CmdGroup(models.Model): diff --git a/jperm/perm_api.py b/jperm/perm_api.py new file mode 100644 index 000000000..cbaede5a3 --- /dev/null +++ b/jperm/perm_api.py @@ -0,0 +1,111 @@ +# coding: utf-8 + +from jasset.models import * +from jumpserver.api import * +import uuid +import re +from ansible.playbook import PlayBook +from ansible import callbacks, utils + + +def get_object_list(model, id_list): + object_list = [] + for object_id in id_list: + if object_id: + object_list.extend(model.objects.filter(id=int(object_id))) + + return object_list + + +def perm_user_handle(user, asset_new, asset_del, group_new, group_del): + username = user.name + asset_group_new = get_object_list(AssetGroup, group_new) + asset_group_del = get_object_list(AssetGroup, group_del) + for asset_group in asset_group_new: + asset_new.extend([asset.ip for asset in asset_group.asset_set.all()]) + + for asset_group in asset_group_del: + asset_del.extend(asset.ip for asset in asset_group.asset_set.all()) + + +def get_rand_file_path(base_dir=os.path.join(BASE_DIR, 'tmp')): + filename = uuid.uuid1().hex + return os.path.join(base_dir, filename) + + +def get_inventory(host_group): + path = get_rand_file_path() + f = open(path, 'w') + for group, host_list in host_group.items(): + f.write('[%s]\n' % group) + for ip in host_list: + asset = get_object(Asset, ip=ip) + if asset.use_default_auth: + f.write('%s ansbile_ssh_port=%s\n' % (ip, asset.port)) + else: + f.write('%s ansible_ssh_port=%s ansible_ssh_user=%s ansbile_ssh_pass=%s\n' + % (ip, asset.port, asset.username, CRYPTOR.decrypt(asset.password))) + f.close() + return path + + +def get_playbook(tempate, var): + str_playbook = open(tempate).read() + for k, v in var.items(): + str_playbook = re.sub(r'%s' % k, v, str_playbook) + path = get_rand_file_path() + f = open(path, 'w') + f.write(str_playbook) + return path + + +def perm_user_api(user, asset_new, asset_del, asset_group_new, asset_group_del): + asset_new_ip = [] + asset_del_ip = [] + + if '' in asset_group_new: + asset_group_new.remove('') + + if '' in asset_group_del: + asset_group_del.remove('') + + asset_new_ip.extend([asset.ip for asset in get_object_list(Asset, asset_new)]) + + for asset_group_id in asset_group_new: + asset_new_ip.extend([asset.ip for asset in get_object(AssetGroup, id=asset_group_id).asset_set.all()]) + + asset_del_ip.extend([asset.ip for asset in get_object_list(Asset, asset_del)]) + + for asset_group_id in asset_group_del: + asset_del_ip.extend([asset.ip for asset in get_object(AssetGroup, id=asset_group_id).asset_set.all()]) + + print asset_new_ip + print asset_del_ip + + stats = callbacks.AggregateStats() + playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY) + runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY) + + if asset_new_ip or asset_del_ip: + host_group = {'new': asset_new_ip, 'del': asset_del_ip} + host_list = get_inventory(host_group) + playbook = get_playbook(os.path.join(BASE_DIR, 'playbook', 'user_perm.yaml'), + {'the_new_group': 'new', 'the_del_group': 'del', + 'the_user': user.username, 'the_pub_key': '/tmp/id_rsa.pub'}) + print host_list, playbook + results = PlayBook(host_list=host_list, + playbook=playbook, + forks=5, + remote_user='web', + remote_pass='redhat', + callbacks=playbook_cb, + runner_callbacks=runner_cb, + stats=stats, + become=True, + become_user='root').run() + + for hostname, result in results.items(): + if result.get('failures', 2): + print "%s >>> Failed" % hostname + else: + print "%s >>> Success" % hostname diff --git a/jperm/urls.py b/jperm/urls.py index c4f398c66..a32025944 100644 --- a/jperm/urls.py +++ b/jperm/urls.py @@ -3,7 +3,8 @@ from jperm.views import * urlpatterns = patterns('jperm.views', # Examples: - (r'^user/$', user_perm), + (r'^user/$', perm_user_list), + (r'^perm_user_edit/$', perm_user_edit), # (r'^dept_perm_edit/$', 'dept_perm_edit'), # (r'^perm_list/$', view_splitter, {'su': perm_list, 'adm': perm_list_adm}), # (r'^dept_perm_list/$', 'dept_perm_list'), diff --git a/jperm/views.py b/jperm/views.py index c098f6b37..fdf95aa0d 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -8,12 +8,58 @@ # from django.template import RequestContext # from jperm.models import Perm, SudoPerm, CmdGroup, Apply from django.db.models import Q +from jperm.models import * from jumpserver.api import * +from jperm.perm_api import * -def user_perm(request): +@require_role('admin') +def perm_user_list(request): header_title, path1, path2 = '用户授权', '授权管理', '用户授权' - return my_render('jperm/user_perm.html', locals(), request) + keyword = request.GET.get('search', '') + users_list = User.objects.all() + + if keyword: + users_list = users_list.filter(Q(name=keyword) | Q(username=keyword)) + users_list, p, users, page_range, current_page, show_first, show_end = pages(users_list, request) + + return my_render('jperm/perm_user_list.html', locals(), request) + + +@require_role('admin') +def perm_user_edit(request): + header_title, path1, path2 = '用户授权', '授权管理', '授权更改' + user_id = request.GET.get('id', '') + user = get_object(User, id=user_id) + asset_all = Asset.objects.all() + asset_group_all = AssetGroup.objects.all() + + asset_id_list = user.assets.split(',') + asset_group_id_list = user.asset_groups.split(',') + if request.method == 'GET' and user: + asset_permed = get_object_list(Asset, asset_id_list) + asset_group_permed = get_object_list(AssetGroup, asset_group_id_list) + assets = [asset for asset in asset_all if asset not in asset_permed] + asset_groups = [asset_group for asset_group in asset_group_all if asset_group not in asset_group_permed] + return my_render('jperm/perm_user_edit.html', locals(), request) + + elif request.method == 'POST' and user: + asset_select = request.POST.getlist('asset_select', []) + asset_group_select = request.POST.getlist('asset_groups_select', []) + asset_new = list(set(asset_select) - set(asset_id_list)) + asset_del = list(set(asset_id_list) - set(asset_select)) + asset_group_new = list(set(asset_group_select) - set(asset_group_id_list)) + asset_group_del = list(set(asset_group_id_list) - set(asset_group_select)) + user.assets = ','.join(asset_select) + user.asset_groups = ','.join(asset_group_select) + user.save() + + perm_user_api(user, asset_new, asset_del, asset_group_new, asset_group_del) + + return HttpResponseRedirect('/jperm/user/') + + else: + return HttpResponse('输入错误') # def asset_cmd_groups_get(asset_groups_select='', cmd_groups_select=''): @@ -51,7 +97,7 @@ def user_perm(request): # perm.user_group = user_groups # perm.asset_group = asset_groups # msg = '添加成功' -# return render_to_response('jperm/user_perm.html', locals(), context_instance=RequestContext(request)) +# return render_to_response('jperm/perm_user_edit.html', locals(), context_instance=RequestContext(request)) # # # def dept_add_asset(dept_id, asset_list): @@ -115,7 +161,7 @@ def user_perm(request): # contact_list = contact_list_confirm # # contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request) -# return render_to_response('jperm/perm_list.html', locals(), context_instance=RequestContext(request)) +# return render_to_response('jperm/perm_user_list.html', locals(), context_instance=RequestContext(request)) # # # @require_admin @@ -147,7 +193,7 @@ def user_perm(request): # contact_list = contact_list_confirm # # contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request) -# return render_to_response('jperm/perm_list.html', locals(), context_instance=RequestContext(request)) +# return render_to_response('jperm/perm_user_list.html', locals(), context_instance=RequestContext(request)) # # # @require_super_user diff --git a/jumpserver/api.py b/jumpserver/api.py index 59411abe4..fcd21c913 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -476,6 +476,10 @@ def get_object(model, **kwargs): use this function for query 使用改封装函数查询数据库 """ + for value in kwargs.values(): + if not value: + return None + the_object = model.objects.filter(**kwargs) if len(the_object) == 1: the_object = the_object[0] diff --git a/jumpserver/models.py b/jumpserver/models.py new file mode 100644 index 000000000..aa186301b --- /dev/null +++ b/jumpserver/models.py @@ -0,0 +1,12 @@ +# coding: utf-8 + +from django.db import models + + +class Setting(models.Model): + default_user = models.CharField(max_length=100, null=True, blank=True) + default_password = models.CharField(max_length=100, null=True, blank=True) + default_pri_key_path = models.CharField(max_length=100, null=True, blank=True) + + class Meta: + db_table = u'setting' \ No newline at end of file diff --git a/jumpserver/urls.py b/jumpserver/urls.py index 617d0351e..6c483ea5b 100644 --- a/jumpserver/urls.py +++ b/jumpserver/urls.py @@ -12,6 +12,7 @@ urlpatterns = patterns('', (r'^logout/$', 'jumpserver.views.logout'), (r'^file/upload/$', 'jumpserver.views.upload'), (r'^file/download/$', 'jumpserver.views.download'), + (r'^setting', 'jumpserver.views.setting'), (r'^error/$', 'jumpserver.views.httperror'), (r'^juser/', include('juser.urls')), (r'^jasset/', include('jasset.urls')), diff --git a/jumpserver/views.py b/jumpserver/views.py index 37784f9c7..9b0ce396c 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -229,6 +229,9 @@ def logout(request): request.session.delete() return HttpResponseRedirect('/login/') + +def setting(request): + return my_render('setting.html', locals(), request) # # def filter_ajax_api(request): # attr = request.GET.get('attr', 'user') diff --git a/juser/models.py b/juser/models.py index 67325ef7f..da61481b2 100644 --- a/juser/models.py +++ b/juser/models.py @@ -32,6 +32,8 @@ class User(models.Model): role = models.CharField(max_length=2, choices=USER_ROLE_CHOICES, default='CU') uuid = models.CharField(max_length=100) group = models.ManyToManyField(UserGroup) + assets = models.TextField(max_length=1000, verbose_name="Assets", default='') + asset_groups = models.CharField(max_length=1000, verbose_name="Asset Groups", default='') ssh_key_pwd = models.CharField(max_length=200) is_active = models.BooleanField(default=True) last_login = models.DateTimeField(null=True) diff --git a/playbook/user_perm.yaml b/playbook/user_perm.yaml new file mode 100644 index 000000000..4aaefa91d --- /dev/null +++ b/playbook/user_perm.yaml @@ -0,0 +1,17 @@ +- hosts: the_new_group + vars: + user: the_user + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=the_pub_key dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + +- hosts: the_del_group + vars: + user: the_user + tasks: + - name: del user + user: name={{ user }} state=absent remove=yes diff --git a/static/js/base.js b/static/js/base.js index 0c5612a0d..5445ab9b6 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -89,7 +89,7 @@ function move(from, to, from_o, to_o) { //} // -function selectAll(){ +function selectAllOption(){ var checklist = document.getElementsByName ("selected"); if(document.getElementById("select_all").checked) { @@ -106,6 +106,12 @@ function selectAll(){ } +function checkAll(formID){ + $('#'+formID+'option').each(function(){ + $(this).attr('checked', true) + }) +} + // //function move_all(from, to){ // $("#"+from).children().each(function(){ diff --git a/templates/jperm/perm_edit.html b/templates/jperm/perm_edit.html index 1b2377bac..33cd1e4eb 100644 --- a/templates/jperm/perm_edit.html +++ b/templates/jperm/perm_edit.html @@ -82,7 +82,7 @@
- +
diff --git a/templates/jperm/user_perm.html b/templates/jperm/perm_user_edit.html similarity index 71% rename from templates/jperm/user_perm.html rename to templates/jperm/perm_user_edit.html index f3a675f39..1b6f491e8 100644 --- a/templates/jperm/user_perm.html +++ b/templates/jperm/perm_user_edit.html @@ -8,7 +8,7 @@
-
主机授权添加
+
{{ user.name }}授权修改
-
+ {% if error %}
{{ error }}
{% endif %} @@ -33,41 +33,48 @@
+
+ + +
+
+ +
+ +
+
- + {% for asset in assets %} + {% endfor %}
-
- - +
+ +
- + {% for asset in asset_permed %} + + {% endfor %}
-
- -
- -
-
- +
+ {% for asset_group in asset_group_permed %} + + {% endfor %}
- -
-
- -
- -
-
-
- +
@@ -130,18 +131,6 @@ $('#sudoPerm').validator({ tip: "输入授权名", ok: "", msg: {required: "必须填写!"} - }, - "user_groups_select": { - rule: "required", - tip: "选择用户组", - ok: "", - msg: {checked: "至少选择一个用户组"} - }, - "asset_groups_select": { - rule: "required", - tip: "选择主机组", - ok: "", - msg: {checked: "至少选择一个主机组"} } }, @@ -156,6 +145,7 @@ $(document).ready(function(){ $('#user_groups_select option').each(function(){ $(this).prop('selected', true) }) + $('#asset_groups_select option').each(function(){ $(this).prop('selected', true) }) diff --git a/templates/jperm/perm_list.html b/templates/jperm/perm_user_list.html similarity index 52% rename from templates/jperm/perm_list.html rename to templates/jperm/perm_user_list.html index 23b6818df..785dbbbbd 100644 --- a/templates/jperm/perm_list.html +++ b/templates/jperm/perm_user_list.html @@ -16,12 +16,6 @@
- @@ -30,13 +24,13 @@
- 添加小组 + 添加用户
@@ -46,27 +40,23 @@ - - - - - - + + + + - {% for group in contacts.object_list %} + {% for user in users.object_list %} - - - - - - + + + + {% endfor %} @@ -75,7 +65,7 @@
- Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries + Showing {{ users.start_index }} to {{ users.end_index }} of {{ p.count }} entries
{% include 'paginator.html' %} @@ -86,23 +76,4 @@
- - {% endblock %} \ No newline at end of file diff --git a/templates/nav.html b/templates/nav.html index 7eb758c3b..ff622f8b7 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -44,6 +44,9 @@
  • 日志审计
  • +
  • + 设置 +
  • diff --git a/templates/setting.html b/templates/setting.html new file mode 100644 index 000000000..991354f7a --- /dev/null +++ b/templates/setting.html @@ -0,0 +1,112 @@ +{% extends 'base.html' %} +{% load mytags %} + + +{% block content %} + {% include 'nav_cat_bar.html' %} +
    +
    +
    +
    +
    +
    项目设置
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + + {% if error %} +
    {{ error }}
    + {% endif %} + {% if msg %} +
    {{ msg }}
    + {% endif %} +
    + +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    +
    +
    + + +
    +
    + +
    + +
    +
    组名所属部门成员数目授权主机组数目授权主机数目备注用户所属用户组授权资产授权资产组 操作
    {{ group.name }} {{ group.dept.name }} {{ group.id | member_count }} {{ group.id | ugrp_perm_agrp_count }} {{ group.id | ugrp_perm_asset_count }} {{ group.comment }} {{ user.name }} {{ user.id }} {{ user.id }} {{ user.comment }} - 详情 - 授权编辑 + 详情 + 编辑
    + + + + + + +
    组名
    +
    + +
    +
    +
    +
    +
    +
    + + + + + +{% endblock %} \ No newline at end of file diff --git a/tmp/147164c46a9611e5a797000c29f7d66e b/tmp/147164c46a9611e5a797000c29f7d66e new file mode 100644 index 000000000..61bfa4c43 --- /dev/null +++ b/tmp/147164c46a9611e5a797000c29f7d66e @@ -0,0 +1,3 @@ +[new] +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat +[del] diff --git a/tmp/14721dba6a9611e5a797000c29f7d66e b/tmp/14721dba6a9611e5a797000c29f7d66e new file mode 100644 index 000000000..3bbd6ba29 --- /dev/null +++ b/tmp/14721dba6a9611e5a797000c29f7d66e @@ -0,0 +1,17 @@ +- hosts: new + vars: + user: admin + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + +- hosts: del + vars: + user: admin + tasks: + - name: del user + user: name={{ user }} state=absent remove=yes diff --git a/tmp/1d0e27de6a9611e5ae2e000c29f7d66e b/tmp/1d0e27de6a9611e5ae2e000c29f7d66e new file mode 100644 index 000000000..7e7718a23 --- /dev/null +++ b/tmp/1d0e27de6a9611e5ae2e000c29f7d66e @@ -0,0 +1,3 @@ +[new] +[del] +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat diff --git a/tmp/1d0e993a6a9611e5ae2e000c29f7d66e b/tmp/1d0e993a6a9611e5ae2e000c29f7d66e new file mode 100644 index 000000000..3bbd6ba29 --- /dev/null +++ b/tmp/1d0e993a6a9611e5ae2e000c29f7d66e @@ -0,0 +1,17 @@ +- hosts: new + vars: + user: admin + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + +- hosts: del + vars: + user: admin + tasks: + - name: del user + user: name={{ user }} state=absent remove=yes diff --git a/tmp/2e6324f46a9511e58276000c29f7d66e b/tmp/2e6324f46a9511e58276000c29f7d66e new file mode 100644 index 000000000..61bfa4c43 --- /dev/null +++ b/tmp/2e6324f46a9511e58276000c29f7d66e @@ -0,0 +1,3 @@ +[new] +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat +[del] diff --git a/tmp/2e63c0b26a9511e58276000c29f7d66e b/tmp/2e63c0b26a9511e58276000c29f7d66e new file mode 100644 index 000000000..ff93b7663 --- /dev/null +++ b/tmp/2e63c0b26a9511e58276000c29f7d66e @@ -0,0 +1,17 @@ +- hosts: new + vars: + user: admin + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + +- hosts: del + vars: + user: admin + tasks: + - name: del user + user: name={{ user }} state=absent diff --git a/tmp/39c5fac46a9511e585f9000c29f7d66e b/tmp/39c5fac46a9511e585f9000c29f7d66e new file mode 100644 index 000000000..7e7718a23 --- /dev/null +++ b/tmp/39c5fac46a9511e585f9000c29f7d66e @@ -0,0 +1,3 @@ +[new] +[del] +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat diff --git a/tmp/39c69db26a9511e585f9000c29f7d66e b/tmp/39c69db26a9511e585f9000c29f7d66e new file mode 100644 index 000000000..ff93b7663 --- /dev/null +++ b/tmp/39c69db26a9511e585f9000c29f7d66e @@ -0,0 +1,17 @@ +- hosts: new + vars: + user: admin + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + +- hosts: del + vars: + user: admin + tasks: + - name: del user + user: name={{ user }} state=absent diff --git a/tmp/3ce93d2c6a9211e5a651000c29f7d66e b/tmp/3ce93d2c6a9211e5a651000c29f7d66e new file mode 100644 index 000000000..8c0ee4573 --- /dev/null +++ b/tmp/3ce93d2c6a9211e5a651000c29f7d66e @@ -0,0 +1,4 @@ +[new] +[del] +127.0.0.1 ansbile_ssh_port=22 +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat diff --git a/tmp/3ceb07b06a9211e5a651000c29f7d66e b/tmp/3ceb07b06a9211e5a651000c29f7d66e new file mode 100644 index 000000000..aa13ef257 --- /dev/null +++ b/tmp/3ceb07b06a9211e5a651000c29f7d66e @@ -0,0 +1,10 @@ +- hosts: new + vars: + user: testfd + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 \ No newline at end of file diff --git a/tmp/48fd55966a9511e59d6b000c29f7d66e b/tmp/48fd55966a9511e59d6b000c29f7d66e new file mode 100644 index 000000000..482b37ae6 --- /dev/null +++ b/tmp/48fd55966a9511e59d6b000c29f7d66e @@ -0,0 +1,4 @@ +[new] +127.0.0.1 ansbile_ssh_port=22 +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat +[del] diff --git a/tmp/48fdf7626a9511e59d6b000c29f7d66e b/tmp/48fdf7626a9511e59d6b000c29f7d66e new file mode 100644 index 000000000..9a17241ca --- /dev/null +++ b/tmp/48fdf7626a9511e59d6b000c29f7d66e @@ -0,0 +1,17 @@ +- hosts: new + vars: + user: testfd + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + +- hosts: del + vars: + user: testfd + tasks: + - name: del user + user: name={{ user }} state=absent diff --git a/tmp/764e1d166a9311e5886c000c29f7d66e b/tmp/764e1d166a9311e5886c000c29f7d66e new file mode 100644 index 000000000..45661fbf3 --- /dev/null +++ b/tmp/764e1d166a9311e5886c000c29f7d66e @@ -0,0 +1,5 @@ +[new] +127.0.0.1 ansbile_ssh_port=22 +[del] +127.0.0.1 ansbile_ssh_port=22 +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat diff --git a/tmp/765012a66a9311e5886c000c29f7d66e b/tmp/765012a66a9311e5886c000c29f7d66e new file mode 100644 index 000000000..9a17241ca --- /dev/null +++ b/tmp/765012a66a9311e5886c000c29f7d66e @@ -0,0 +1,17 @@ +- hosts: new + vars: + user: testfd + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + +- hosts: del + vars: + user: testfd + tasks: + - name: del user + user: name={{ user }} state=absent diff --git a/tmp/aa4bd3526a9211e5a53f000c29f7d66e b/tmp/aa4bd3526a9211e5a53f000c29f7d66e new file mode 100644 index 000000000..482b37ae6 --- /dev/null +++ b/tmp/aa4bd3526a9211e5a53f000c29f7d66e @@ -0,0 +1,4 @@ +[new] +127.0.0.1 ansbile_ssh_port=22 +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat +[del] diff --git a/tmp/aa4cbc546a9211e5a53f000c29f7d66e b/tmp/aa4cbc546a9211e5a53f000c29f7d66e new file mode 100644 index 000000000..aa13ef257 --- /dev/null +++ b/tmp/aa4cbc546a9211e5a53f000c29f7d66e @@ -0,0 +1,10 @@ +- hosts: new + vars: + user: testfd + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 \ No newline at end of file diff --git a/tmp/bbd799fa6a9511e59e68000c29f7d66e b/tmp/bbd799fa6a9511e59e68000c29f7d66e new file mode 100644 index 000000000..61bfa4c43 --- /dev/null +++ b/tmp/bbd799fa6a9511e59e68000c29f7d66e @@ -0,0 +1,3 @@ +[new] +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat +[del] diff --git a/tmp/bbd931026a9511e59e68000c29f7d66e b/tmp/bbd931026a9511e59e68000c29f7d66e new file mode 100644 index 000000000..3bbd6ba29 --- /dev/null +++ b/tmp/bbd931026a9511e59e68000c29f7d66e @@ -0,0 +1,17 @@ +- hosts: new + vars: + user: admin + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + +- hosts: del + vars: + user: admin + tasks: + - name: del user + user: name={{ user }} state=absent remove=yes diff --git a/tmp/c2774ea46a9511e5be00000c29f7d66e b/tmp/c2774ea46a9511e5be00000c29f7d66e new file mode 100644 index 000000000..7e7718a23 --- /dev/null +++ b/tmp/c2774ea46a9511e5be00000c29f7d66e @@ -0,0 +1,3 @@ +[new] +[del] +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat diff --git a/tmp/c2780ae26a9511e5be00000c29f7d66e b/tmp/c2780ae26a9511e5be00000c29f7d66e new file mode 100644 index 000000000..3bbd6ba29 --- /dev/null +++ b/tmp/c2780ae26a9511e5be00000c29f7d66e @@ -0,0 +1,17 @@ +- hosts: new + vars: + user: admin + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + +- hosts: del + vars: + user: admin + tasks: + - name: del user + user: name={{ user }} state=absent remove=yes diff --git a/tmp/c6a8384a6a8a11e5b929000c29f7d66e b/tmp/c6a8384a6a8a11e5b929000c29f7d66e new file mode 100644 index 000000000..89c7aa8ed --- /dev/null +++ b/tmp/c6a8384a6a8a11e5b929000c29f7d66e @@ -0,0 +1,11 @@ +- hosts: hello world + vars: + user: testuserssss + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + diff --git a/tmp/d3e0469c6a8511e5ae99000c29f7d66e b/tmp/d3e0469c6a8511e5ae99000c29f7d66e new file mode 100644 index 000000000..be37d2580 --- /dev/null +++ b/tmp/d3e0469c6a8511e5ae99000c29f7d66e @@ -0,0 +1,6 @@ +[world] +125.39.8.222 ansbile_ssh_port=2234 +202.106.0.20 ansbile_ssh_port=22 +[hello] +125.39.8.222 ansbile_ssh_port=2234 +202.106.0.20 ansbile_ssh_port=22 diff --git a/tmp/f8b99a686a9411e5b0fb000c29f7d66e b/tmp/f8b99a686a9411e5b0fb000c29f7d66e new file mode 100644 index 000000000..61bfa4c43 --- /dev/null +++ b/tmp/f8b99a686a9411e5b0fb000c29f7d66e @@ -0,0 +1,3 @@ +[new] +192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat +[del] diff --git a/tmp/f8bb07546a9411e5b0fb000c29f7d66e b/tmp/f8bb07546a9411e5b0fb000c29f7d66e new file mode 100644 index 000000000..ff93b7663 --- /dev/null +++ b/tmp/f8bb07546a9411e5b0fb000c29f7d66e @@ -0,0 +1,17 @@ +- hosts: new + vars: + user: admin + tasks: + - name: add user + user: name={{ user }} state=present + - name: .ssh direcotory + file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory + - name: set authorizied_file + copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600 + +- hosts: del + vars: + user: admin + tasks: + - name: del user + user: name={{ user }} state=absent