ansible_模块和剧本ansible_bookplay
发布时间:2020-12-15 18:20:46 所属栏目:安全 来源:网络整理
导读:ansible_second_day 软件相关模块 yum rpm 和 yum 的区别 rpm:redhat package manager yum可以解决依赖关系 yum 源配置 ansible web -m copy -a ‘src=/etc/yum.repos.d/epel.repo dest=/etc/yum.repos.d/epel‘ [epel]name=Extra Packages for Enterprise L
ansible_second_day软件相关模块yum
pippip install 安装包 pip freeze > a.txt 将python的环境打包到文件中 pip install -r a.txt 安装文件中的包 pip list 查看所有已经安装成功的包 ansible web -m pip -a ‘name=flask‘ # 安装flask模块 serviceps -ef |grep nginx # 查看进程 ss -tunpl # 查看端口信息 systemctl start nginx # centos7 service nginx start # centos6 systemctl enabled nginx # centos7 开机启动 chkconfig nginx on # centos6 开机启动 ansible web -m service -a ‘namme=nginx state=started‘ # 启动nginx ansible web -m service -a ‘name=nginx state=stopped‘ # 关闭nginx corn计划任务 * * * * * job 分 时 日 月 周 mission 任务 0 */2 * * * misssion 每隔俩个小时 0 12,13 * * * mission 12点和13点 0 12-17 * * * mission 12点到17点 0 12-17/2 * * 1,3,6,0 周1,周3,周6,周7 12点到17点每隔俩小时 执行mission crontab -e # 编辑计划任务 crontab -l # 查看计划任务 crontab -r # 删除计划任务 参数 day 天 disabled 禁言 落实到代码上就是在任务前面加# 注释掉 hour 小时 job 任务 minute 分钟 mouth 月 name 任务名称 weekday 周 ansible db - m cron -a ‘minute=39 job="touch /tmp/zhu.txt" name=fouchfile‘ # 新建一个计划任务 ansible db - m cron -a ‘name=touchfile state=abesnt‘ # 删除一个计划任务 ansible db -m cron -a ‘minute=26 job="mkdir zzz" name = touchfile disabled=yes‘ # 禁用计划任务,以#表示禁用 user用户 : 管理员 root 0 普通用户 系统用户 不能登录 1-999 centos7 1-499 centos6 登录用户 可以登录 1000-65535 centos7 500-65535 centos6 用户组: 系统管理员组 root 0 系统用户组 1-999 centos7 1-499 centos6 登录用户组 1000-65535 centos7 500-65535 centos6 -d 指定用户的家目录 -g 指定用户组 -G 执行用户的附加组 -s 指定登陆后使用的shell -r 穿件一个系统组 useradd -r max 创建系统用户,从999倒叙计数 useradd -s /sbin/nologin max # 创建的是普通用户,计数从 1000开始升序 useradd -d /opt/max1 max2 # 创建用户时并指定用户的家目录 useradd -u 8888 max # 创建用户并指定用户的uid userdel max # 删除用户max 只在系统中删除了用户 用户家目录还在 userdel -r max # 删除用户并且删除用户家目录 groupadd earl # 创建用户组 groupdel earl # 删除用户组 group # 组 groups # 附加组 home # 家目录 name # 用户名 password # 密码 remove # 删除 shell # 登录后使用的shell system # 创建一个系统用户 uid # 用来指定用户的id state # 状态 ansible db -m user -a‘name=max uid=3333 home=/opt/max groups=root shell=/sbin/nologin‘ # 创建一个用户,指定用户的id,用户的家目录,用户的附加组,用户的shell ansible db -m user -a ‘name=max state=absent‘ # 删除用户但是留下用户的家目录 ansible db -m user -a ‘name=maex state=absent remove=yes‘ # 删除用户同时并且删除用户的家目录 groupgid # 组id name # 组名 system # 系统组 state # 状态 ansible db -m group -a ‘name=max system=yes‘ # 创建系统组 ansible db -m group -a ‘name=max state=absent‘ # 删除组 web ansible web -m group -a ‘name=max8‘ # 创建一个用户组 max8 ansible web -m user -a ‘name=eral10‘ # 创建一个用户 eral8 ansible web -m copy -a ‘src=/etc/ftp dest=/tmp/f‘ # 把/etc/ftp 文件复制到远程主机上 /tmp/f 下 ansible web -m yum -a ‘name=nginx‘ # 安装nginx ansible web -m service -a ‘name=nginx enabled=yes‘ # 设置nginx 开机启动 ansible剧本yaml是一个编程语言 xml 是用来写配置文件的一个语言 ini yaml 字典 : key:value 列表 : [] - 后缀名 : yaml,yml ansible-playbook 命令格式执行顺序,从上往下 特性: 幂等性,执行多少次,结果都一样 ansible-playbook [options] playbook.yml [playbook2...] -C,--check # 检查,演示一遍,但不是真的运行,白干活 -f FORKS,--forks=FORKS # 用来做并发 --list-hosts # 列出主机列表 --syntax-check # 语法检测 简单使用 - hosts: web tasks: - name: creategroup group: name=max9 - name: createuser user: name=eral9 传参-hosts: web taseks: -name: create{{ user}} user: name={{user}} first ansible-play -e ‘user=max888‘ p1.yml second [db] 192.168.111.129 user=max777 195.168.107.133 user=max888 third [db:vars] # 表示组的参数 user=max777 fourth - host: db vars: - user: max666 tasks: - name: create{{ user }} user: name= {{ user }} fifth - hosts: db tasks: - name: sum shell: echo 7+8|bc register: user - name: createuser user: name={{ user.sudout }} 传递参数的优先级 -e >>> playbook vars > hosts文件 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |