ansible

06Ansible角色

自闭症网瘾萝莉.ら 提交于 2020-03-28 19:48:01
Ansible角色 roles是在ansible中,playbooks的目录组织结构。 而模块化之后,成为roles的组织结构,易读,代码可重用,层次清晰。 需求:通过role远程部署nginx并配置 准备目录结构 [root@ansible-server ~]# mkdir -p /tmp/roles/nginx/{files,handlers,tasks,templates,vars} [root@ansible-server ~]# touch /tmp/roles/site.yaml [root@ansible-server ~]# touch /tmp/roles/nginx/{handlers,tasks,vars}/main.yaml [root@ansible-server ~]# echo 1234 > roles/nginx/files/index.html [root@ansible-server ~]# yum install -y nginx && cp /etc/nginx/nginx.conf roles/nginx/templates/nginx.conf.j2 [root@ansible-server ~]# tree /tmp/roles/ /tmp/roles/ ├── nginx │ ├── files │ │ └── index.html

ansible命令应用基础

好久不见. 提交于 2020-03-27 23:05:25
ansible命令应用基础: Usage: ansible <host-pattern> [-f forks] [-m module_name][-a args] -f forks:启动的并发线程数 -m module_name:要使用的模块 -a args:模块特有的参数 常见模块: ansible-doc -s 模块 --查看模块使用参数 command:命令模块,默认模块,用于在远程执行命令: # ansible all -a 'ping' cron: 定时模块 state: present,latest表示安装,absent表示卸载 # ansible web -m cron -a 'minute="*/2" job="/bin/echo hello" name="test cron job"' minute表示分钟,hour表示小时,day表示日期,month表示月份,weekday表示周,如果没写则默认为 * 删除cron计划 ansible testhost -m cron -a "name='test cron' state=absent" user: 定义用户模块 name=: 指明创建的用户的名字 # ansible web -m user -a 'name=mysql uid=306 system=yes group=mysql' group=: 创建组 #

2016年度计划

孤者浪人 提交于 2020-03-27 15:37:44
3 月,跳不动了?>>> 1. python 有关 1.1 virtualenv 用于创建一个隔离的Python环境,一个专属于项目的python环境。用virtualenv 来保持一个干净的环境非常有用 https://virtualenv.pypa.io/en/latest/ http://www.virtualenv.org/en/latest/index.html 一些博文: 用pyenv和virtualenv搭建单机多版本python虚拟开发环境 http://www.it165.net/pro/html/201405/13603.html 1.2 pyenv https://github.com/yyuu/pyenv https://github.com/yyuu/pyenv-virtualenv ## INSTALL pyenv git clone https://github.com/yyuu/pyenv.git ~/.pyenv echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

ansible在playbook中变量传入到执行脚本的方法

匆匆过客 提交于 2020-03-27 15:31:52
3 月,跳不动了?>>> 简介 这个方式用于ansible调用playbook方法实现远程服务器执行某个脚本,脚本中的某些参数需要由管理服务器传入的情况。 下面的例子是ansible实际调用script模块实现远程服务器执行一个shell脚本 脚本内容 ansible 执行脚本 #!/usr/bin/env python # -*- coding:utf-8 -*- # edit: mesopodamia@gmail.com import ansible from ansible.playbook import PlayBook from ansible.inventory import Inventory from ansible import callbacks from ansible import utils import sys reload(sys) sys.setdefaultencoding('utf-8') vars = "hello world" ansible_command = "/usr/local/bin/ansible-playbook" playbook = "/home/eric/playbook/deploy.yml" hosts = ['192.168.0.99'] # Boilerplace callbacks for stdout

解决Ansible安装依赖问题

允我心安 提交于 2020-03-26 11:14:39
由于每台机器的环境都不尽相同,存在某些机器的yum源太小或者所带软件版本太低或缺失等问题,所以在安装软件时也可能会产生不同的依赖报错。下面我就以安装ansible时自身遇到过的依赖问题解决方法作介绍,只介绍解决依赖部分内容,安装ansible详细过程另请自行百度。 一、 使用ansible --version Ansible并未安装完成,存在依赖问题。 附报错内容: ERROR! Unexpected Exception, this is probably a bug: (cryptography 1.3.1 (/usr/lib64/python2.7/site-packages), Requirement.parse('cryptography>=1.5')) the full traceback was: Traceback (most recent call last): File "/usr/bin/ansible", line 97, in <module> mycli = getattr( import ("ansible.cli.%s" % sub, fromlist=[myclass]), myclass) File "/usr/lib/python2.7/site-packages/ansible/cli/ init .py", line 38, in

Ansible自动化运维学习之五:Ansible配置文件详解与调优

邮差的信 提交于 2020-03-25 02:00:50
一、常用参数详解 本文对 https://blog.51cto.com/8355320/2471354 的参数配置进行了扩充。 Ansible默认配置文件为/etc/ansible/ansible.cfg,配置文件中可以对ansible进行各项参数的调整,包括并发线程、用户、模块路径、配置优化等,常用参数如下: [defaults] inventory = /etc/ansible/hosts 被控端IP信息列表; library = /usr/share/my_modules/ Ansible默认模块的位置; remote_tmp = $HOME/.ansible/tmp Ansible远程主机执行临时文件路径; pattern = * 匹配对所有主机通信; forks = 5 默认并行进程数量; poll_interval = 15 默认轮训间隔时间; sudo_user = root sudo远程主机执行用户名(需要配置sudo权限); ask_sudo_pass = True 使用sudo时是否需要输入root密码; ask_pass = True 是否需输入密码(配置免密登录); transport = smart 与远程机的传输机制; remote_port = 22 默认远程SSH连接端口; module_lang = C 模块和系统之间通信时使用的语言;

Ansible自动部署tomcat

非 Y 不嫁゛ 提交于 2020-03-24 23:07:33
1、首先准备3台机器 ansible机器:192.168.52.34 目标主机:192.168.52.35 目标主机:192.168.52.36 2、关闭防火墙 [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# setenforce 0 3、配置免密登录 4、安装ansible yum -y install ansible 5、在ansible的配置文件中添加目标主机 vim /etc/ansible/hosts ## [webservers] ## alpha.example.org ## beta.example.org ## 192.168.1.100 ## 192.168.1.110 [tomcat] 192.168.52.35 192.168.52.36 # If you have multiple hosts following a pattern you can specify # them like this: ## www[001:006].example.com 6、检查ansible与目标主机是否连通 7、上传tomcat、jdk [root@localhost ~]# rz [root@localhost ~]# rz [root@localhost ~]# ls

ansible部署Tomcat

非 Y 不嫁゛ 提交于 2020-03-24 15:02:38
首先要准备的环境就是免密登录 这是要在ansible-playbook中所写的内容---- hosts: tomcat tasks: - name: 关闭防火墙 service: name=iptables state=stopped - name: 关闭selinux shell: setenforce 0 - name: 安装所需的软件 yum: name=tar,libselinux-python state=latest - name: 推送jdk java环境 copy: src=jdk-8u131-linux-x64_.rpm dest=/root - name: 创建文件夹 file: path=/opt/tomcat state=directory - name: 推送tomcat的压缩包 unarchive: src=apache-tomcat-8.5.35.tar.gz dest=/opt/tomcat - name: 安装jdk yum: name=jdk-8u131-linux-x64_.rpm state=installed - name: 启动tomcat shell: nohup /opt/tomcat/apache-tomcat-8.5.35/bin/startup.sh & 来源: https://www.cnblogs.com/xianglei_

ansible-2.9.6 最新版本离线安装

荒凉一梦 提交于 2020-03-23 22:45:12
无需多言,直接看脚本。在系统CentOS7上完美运行。 所有软件包: 链接: https://pan.baidu.com/s/1wKNO0DDQe1nDG6jPhb4P0w 提取码:3i2v #!/bin/bash # 本地源或光盘挂载方式安装 yum install -y python-devel openssl-devel gcc libffi-devel # 1.创建文件夹 mkdir -p /usr/local/src/ansible # 2. 安装setuptools cd /usr/local/src/ansible unzip setuptools-44.1.0.zip cd setuptools-44.1.0 python setup.py install # 3. 安装pycrypto cd /usr/local/src/ansible tar xvzf pycrypto-2.6.1.tar.gz cd pycrypto-2.6.1 python setup.py install # 4. 安装yaml cd /usr/local/src/ansible tar xvzf yaml-0.1.5.tar.gz cd yaml-0.1.5 ./configure --prefix=/usr/local make --jobs=`grep processor /proc

03.yaml语法和playbook写法

巧了我就是萌 提交于 2020-03-23 17:38:20
ansible的playbook采用yaml语法,它简单地实现了json格式的事件描述。yaml之于json就像markdown之于html一样,极度简化了json的书写。在学习ansible playbook之前,很有必要把yaml的语法格式、引用方式做个梳理。 1.1 初步说明 以一个简单的playbook为例,说明yaml的基本语法。 --- - hosts: 192.168.100.59,192.168.100.65 remote_user: root pre_tasks: - name: set epel repo for Centos 7 yum_repository: name: epel7 description: epel7 on CentOS 7 baseurl: http://mirrors.aliyun.com/epel/7/$basearch/ gpgcheck: no enabled: True tasks: # install nginx and run it - name: install nginx yum: name=nginx state=installed update_cache=yes - name: start nginx service: name=nginx state=started post_tasks: - shell: