FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


os:linux:user:index.html



Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
os:linux:user:index.html [2018/01/06 00:28]
kurihara
os:linux:user:index.html [2019/02/11 00:39] (current)
kurihara
Line 1: Line 1:
 [[:index.html#OS Management|Top#OS Management]] [[:index.html#OS Management|Top#OS Management]]
-====== User Management (user.py)=====+====== Linux User Management with Fabric (user.py)=====
  
 $FHHOME/fabfile/user.py $FHHOME/fabfile/user.py
Line 7: Line 7:
 \\ \\
  
-===== Operation =====+===== Operation with Fabric ===== 
 +==== print list of possible commands ====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab  -l |grep user+$ fab -l |grep -F  user. 
 +    user.check_group               user.check_group:group01 
 +    user.check_user                user.check_user:user01 
 +    user.chpasswd_devuser01_pro 
 +    user.chpasswd_devuser01_qa 
 +    user.chpasswd_devuser01_stg 
 +    user.chpasswd_devuser02_pro 
 +    user.chpasswd_devuser02_stg 
 +    user.chpasswd_devuser03_pro 
 +    user.chpasswd_root_pro         PASSWORD is E5*******5 
 +    user.chpasswd_root_qa          PASSWORD is AW*******5 
 +    user.chpasswd_root_stg         PASSWORD is S3*******! 
 +    user.useradd_dev_all 
 +    user.useradd_devuser01 
 +    user.useradd_devuser02 
 +    user.useradd_opeuser01 
 +    user.userdel_devuser01 
 +    user.userdel_devuser02 
 +</sxh>
  
-$ fab  -H $H auth.pro  user.check_user:user01+==== Example ==== 
 + 
 +<sxh bash toolbar:false gutter:false> 
 +$ fab  -H $H   user.check_user:user01 
 +$ echo x.x.x.x | fab    user.check_user:user01
 </sxh> </sxh>
  
  
 +==== Fabric one-line Task Examples====
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
 $ H=test-server-1 $ H=test-server-1
  
-$ fab -H $H auth.pro -- hostname+$ fab -H $H  -- hostname 
 + 
 +$ fab -H $H  -- id user01 
 +$ fab -H $H  -- "cat /etc/passwd |grep user01"   # check login shell 
 +$ fab -H $H  -- grep user01 /etc/group
  
-$ fab -H $H auth.pro -- id user01 +$ fab -H $H  -- sudo gpasswd -a user1 sudo  add USER to GROUP 
-$ fab -H $H auth.pro -"cat /etc/passwd |grep user01"   check login shell +$ fab -H $H  -- sudo gpasswd -r user1 sudo  # remove USER from GROUP
-$ fab -H $H auth.pro -- grep user01 /etc/group+
 </sxh> </sxh>
  
Line 47: Line 74:
  
 <sxh python toolbar:false gutter:false> <sxh python toolbar:false gutter:false>
-import sys+import sys, os
 from fabric.api import * from fabric.api import *
 from fabric.contrib import files from fabric.contrib import files
 from fabric.utils import abort from fabric.utils import abort
 +
 +FHHOME=os.environ["FHHOME"]
  
 #==================================================================== #====================================================================
Line 60: Line 89:
 @task  @task 
 def check_user(user): def check_user(user):
-    """fab  auth.pro  check_user:user01"""+    """user.check_user:user01"""
     res = run("id %s" % user, warn_only=True)     res = run("id %s" % user, warn_only=True)
     if res.failed is True:     if res.failed is True:
Line 72: Line 101:
 @task  @task 
 def check_group(group): def check_group(group):
-    """fab  auth.pro  check_group:group01""" +    """user.check_group:group01""" 
-    res = run("grep %s /etc/group" % group, warn_only=True)+    res = run("grep ^%s /etc/group" % group, warn_only=True)
     if res.failed is True:     if res.failed is True:
         puts(red("There isn't %s in %s." % (group, env.host_string)))         puts(red("There isn't %s in %s." % (group, env.host_string)))
Line 176: Line 205:
     sudo("id devuser02 && echo 'devuser02:PASS' | chpasswd", warn_only=True)     sudo("id devuser02 && echo 'devuser02:PASS' | chpasswd", warn_only=True)
  
 +
 +# user.chpasswd_devuser02_stg
 +@task
 +def chpasswd_devuser02_stg():
 +    sudo("id devuser02 && echo 'devuser02:PASS' | chpasswd", warn_only=True)
  
 #------------------------------------------------ #------------------------------------------------
Line 205: Line 239:
         sudo("userdel -r devuser02")         sudo("userdel -r devuser02")
         return         return
- 
- 
-#==================================================================== 
-# etc 
-#==================================================================== 
  
  


os/linux/user/index.html.1515166106.txt.gz · Last modified: 2018/01/06 00:28 by kurihara