【playbook剧本批量创建用户,密码】【playbook剧本同时安装nginx,httpd能启动】【批量部署Jdk+Tomcat+Jenkins剧本】

本文主要是介绍【playbook剧本批量创建用户,密码】【playbook剧本同时安装nginx,httpd能启动】【批量部署Jdk+Tomcat+Jenkins剧本】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

    • 创建10个用户分别是user1--user10,并设置密码为123456789要求playbook剧本编写
    • 安装httpd与nginx服务,要求httpd与nginx均可同时开启,访问nginx的页面是“hello nginx”、访问httpd的页面是“hello Apache”。
    • 在测试安装 nginx 80 端口
    • 重点结合到一个剧本里面
    • 批量部署Jdk+Tomcat+Jenkins
    • 下面是剧本
  • 安装tomcat
  • 安装jenkins

创建10个用户分别是user1–user10,并设置密码为123456789要求playbook剧本编写

步骤语法;

  • hosts: web2
    user: root
    tasks:
    • name: 创建10个用户
      user: name={{ item.name }} password={{ item.chpass | password_hash(‘sha512’) }} update_password=always
      with_items:
      • { name: ‘test’,chpass: ‘123456789’}
      • { name: ‘test2’,chpass: ‘123456789’}
      • { name: ‘test3’,chpass: ‘123456789’}
      • { name: ‘test4’,chpass: ‘123456789’}
      • { name: ‘test5’,chpass: ‘123456789’}
      • { name: ‘test6’,chpass: ‘123456789’}
      • { name: ‘test7’,chpass: ‘123456789’}
      • { name: ‘test8’,chpass: ‘123456789’}
      • { name: ‘test9’,chpass: ‘123456789’}
      • { name: ‘test10’,chpass: ‘123456789’}

在这里插入图片描述
在这里插入图片描述
脚本检测
在这里插入图片描述

安装httpd与nginx服务,要求httpd与nginx均可同时开启,访问nginx的页面是“hello nginx”、访问httpd的页面是“hello Apache”。

步骤1,;先测试 httpd 修改城端口8080 测试查看
先编写 httpd 的主配置文件 修改端口号 保存成文件
在这里插入图片描述
在这里插入图片描述
进行剧本 编写

  • hosts: web3
    user: root
    vars_files:
    • /root/httpd.yml
      tasks:
    • name: 安装apache
      yum: name=httpd state=latest
    • name: 在默认发布目录输入内容
      shell: echo " hello Apache" >> /var/www/html/index.html
    • name: 拷贝修改端口文件
      copy: src={{ src_path }} dest={{ dest_path }}
    • name: 启动 httpd
      service: name=httpd state=started
      在这里插入图片描述
      查看测试成功
      在这里插入图片描述

在测试安装 nginx 80 端口

我这里采用yum 安装的需要编写yum.repo文件

第一步重点 下载的是稳定版本
[nginx]
name=nginx
baseurl=http://nginx.org/packages/centos/ r e l e a s e v e r / releasever/ releasever/basearch/
gpgcheck=0
enabled=1
在这里插入图片描述
编写的变量文件
在这里插入图片描述
进行剧本编写

  • hosts: web3
    user: root
    vars_files:
    • /root/yum-utils9.yml
      tasks:
    • name: 安装yum-utils
      yum: name=yum-utils state=latest
    • name: 拷贝nginx.repo文件
      copy: src={{ src_pat }} dest={{ dest_pat }}
    • name: 安装nginx
      yum: name=nginx state=latest
    • name: 输入一句话
      shell: echo “hello nginx” > /usr/share/nginx/html/index.html
      notify: start nginx
      handlers:
    • name: start nginx
      service: name=nginx state=started
      在这里插入图片描述
      进行测试
      在这里插入图片描述

重点结合到一个剧本里面

语法;

  • hosts: web3
    user: root
    vars_files:

    • /root/httpd.yml
      tasks:
    • name: 安装apache
      yum: name=httpd state=latest
    • name: 在默认发布目录输入内容
      shell: echo " hello Apache" >> /var/www/html/index.html
    • name: 拷贝修改端口文件
      copy: src={{ src_path }} dest={{ dest_path }}
    • name: 启动 httpd
      service: name=httpd state=started
  • hosts: web3
    user: root
    vars_files:

    • /root/yum-utils9.yml
      tasks:
    • name: 安装yum-utils
      yum: name=yum-utils state=latest
    • name: 拷贝nginx.repo文件
      copy: src={{ src_path }} dest={{ dest_path }}
    • name: 安装nginx
      yum: name=nginx state=latest
    • name: 输入一句话
      shell: echo “hello nginx” > /usr/share/nginx/html/index.html
    • name: 启动 nginx
      service: name=nginx state=started
      在这里插入图片描述
      查看检测端口
      在这里插入图片描述

批量部署Jdk+Tomcat+Jenkins

步骤 1;
将Jdk、Tomcat、Jenkins的安装包上传到ansbile控制节点的/root下
[root@ansible ansible]# ls
在这里插入图片描述
步骤2;
[root@java-server ansible]# head -2 /root/startup.sh //startup.sh是tomcat的启动脚本
#!/bin/sh
source /etc/profile #加上此行,是为了启动加载到环境变量

步骤3;编写一个变量文件
变量文件
[root@ansible ansible]# cat /root/file.yml
在这里插入图片描述

下面是剧本

语法;

  • hosts: web2
    user: root
    vars_files:
    • /root/zuoye/file.yml
      tasks:
      ##配置JDK,上传jdk、tomcat的安装包到/usr/src
    • name: 传送jdk
      copy: src={{ src_jdk_path }} dest={{ dest_jdk_path }}
    • name: 解压jdk
      shell: tar -xvzf /usr/src/jdk-8u211-linux-x64.tar.gz -C /usr/local
    • name: 移动改名 java
      shell: mv /usr/local/jdk1.8.0_211 /usr/local/java
    • name: 加入环境变量
      shell: echo “JAVA_HOME=/usr/local/java” >> /etc/profile
    • name: 加入环境变量2
      shell: echo ‘PATH= J A V A H O M E / b i n : JAVA_HOME/bin: JAVAHOME/bin:PATH’ >> /etc/profile

安装tomcat

  • name: 拷贝 tomcat
    copy: src={{ src_tomcat_path }} dest={{ dest_tomcat_path }}
  • name: 解压 tomcat
    shell: tar -xvzf /usr/src/apache-tomcat-8.5.45.tar.gz -C /usr/local
  • name: 移动改名 tomcat
    shell: mv /usr/local/apache-tomcat-8.5.45 /usr/local/tomcat
  • name: 加入变量文件 file
    copy: src=/root/startup.sh dest=/usr/local/tomcat/bin

安装jenkins

  • name: 拷贝 jenkins
    copy: src=/root/jenkins.war dest=/usr/local/tomcat/webapps/
    notify: start jenkins
    handlers:
  • name: start jenkins

语法检测
在这里插入图片描述
在这里插入图片描述

测试 节点 8080端口 192.168.150.174:8080
在这里插入图片描述
测试 jenkins 192.168.150.174:8080/jenkins
在这里插入图片描述

这篇关于【playbook剧本批量创建用户,密码】【playbook剧本同时安装nginx,httpd能启动】【批量部署Jdk+Tomcat+Jenkins剧本】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/875821

相关文章

springboot上传zip包并解压至服务器nginx目录方式

《springboot上传zip包并解压至服务器nginx目录方式》:本文主要介绍springboot上传zip包并解压至服务器nginx目录方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录springboot上传zip包并解压至服务器nginx目录1.首先需要引入zip相关jar包2.然

如何使用Nginx配置将80端口重定向到443端口

《如何使用Nginx配置将80端口重定向到443端口》这篇文章主要为大家详细介绍了如何将Nginx配置为将HTTP(80端口)请求重定向到HTTPS(443端口),文中的示例代码讲解详细,有需要的小伙... 目录1. 创建或编辑Nginx配置文件2. 配置HTTP重定向到HTTPS3. 配置HTTPS服务器

如何在Mac上安装并配置JDK环境变量详细步骤

《如何在Mac上安装并配置JDK环境变量详细步骤》:本文主要介绍如何在Mac上安装并配置JDK环境变量详细步骤,包括下载JDK、安装JDK、配置环境变量、验证JDK配置以及可选地设置PowerSh... 目录步骤 1:下载JDK步骤 2:安装JDK步骤 3:配置环境变量1. 编辑~/.zshrc(对于zsh

如何在pycharm安装torch包

《如何在pycharm安装torch包》:本文主要介绍如何在pycharm安装torch包方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录在pycharm安装torch包适http://www.chinasem.cn配于我电脑的指令为适用的torch包为总结在p

在PyCharm中安装PyTorch、torchvision和OpenCV详解

《在PyCharm中安装PyTorch、torchvision和OpenCV详解》:本文主要介绍在PyCharm中安装PyTorch、torchvision和OpenCV方式,具有很好的参考价值,... 目录PyCharm安装PyTorch、torchvision和OpenCV安装python安装PyTor

Python Transformer 库安装配置及使用方法

《PythonTransformer库安装配置及使用方法》HuggingFaceTransformers是自然语言处理(NLP)领域最流行的开源库之一,支持基于Transformer架构的预训练模... 目录python 中的 Transformer 库及使用方法一、库的概述二、安装与配置三、基础使用:Pi

Redis在windows环境下如何启动

《Redis在windows环境下如何启动》:本文主要介绍Redis在windows环境下如何启动的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Redis在Windows环境下启动1.在redis的安装目录下2.输入·redis-server.exe

Spring Boot项目部署命令java -jar的各种参数及作用详解

《SpringBoot项目部署命令java-jar的各种参数及作用详解》:本文主要介绍SpringBoot项目部署命令java-jar的各种参数及作用的相关资料,包括设置内存大小、垃圾回收... 目录前言一、基础命令结构二、常见的 Java 命令参数1. 设置内存大小2. 配置垃圾回收器3. 配置线程栈大小

解决SpringBoot启动报错:Failed to load property source from location 'classpath:/application.yml'

《解决SpringBoot启动报错:Failedtoloadpropertysourcefromlocationclasspath:/application.yml问题》这篇文章主要介绍... 目录在启动SpringBoot项目时报如下错误原因可能是1.yml中语法错误2.yml文件格式是GBK总结在启动S

Python从零打造高安全密码管理器

《Python从零打造高安全密码管理器》在数字化时代,每人平均需要管理近百个账号密码,本文将带大家深入剖析一个基于Python的高安全性密码管理器实现方案,感兴趣的小伙伴可以参考一下... 目录一、前言:为什么我们需要专属密码管理器二、系统架构设计2.1 安全加密体系2.2 密码强度策略三、核心功能实现详解