ansible

Ansible group vars priority

自古美人都是妖i 提交于 2020-01-23 05:10:41
问题 Let's say I have 3 files in group_vars: abc.yml all.yml xyz.yml And the same variable defined in them: - my_var: abc - my_var: all - my_var: xyz Ansible documentation says: Within any section, redefining a var will overwrite the previous instance. If multiple groups have the same variable, the last one loaded wins. If you define a variable twice in a play’s vars: section, the 2nd one wins. Does it mean that load order is alphabetical one and abc.yml has the lowest priority, whereas xyz.yml

ansible部署tomcat

血红的双手。 提交于 2020-01-22 22:14:09
copy不过去在6的机器上安装jdk.rpm ansible webservers -m shell -a ‘rpm -ivh jdk-8u20-linux-x64.rpm’ ansible webservers -m shell -a ‘java -version’ ansible webservers -m file -a ‘path=/opt/tomcat state=directory’ ansible webservers -m unarchive -a ‘src=apache-tomcat-8.5.35.tar.gz dest=/opt/tomcat/’ ansible webservers -m shell -a ‘nohup /opt/tomcat/apache-tomcat-8.5.35/bin/startup.sh &’ ansible webservers -m shell -a ‘ss -lnt|grep 8080’ docker inspect web1 查看ip地址 来源: CSDN 作者: .鲸鱼. 链接: https://blog.csdn.net/dongxuej/article/details/103778754

ansible笔记——安装配置ansible

ぃ、小莉子 提交于 2020-01-22 18:57:07
1、安装ansible centos安装ansible如下: [root@ansible ~]# yum -y install epel-release [root@ansible ~]# yum -y install ansible [root@ansible ~]# ansible --version #安装的版本为2.9 ansible 2.9.2 2、ansible参数补全功能 从ansible 2.9版本开始,它支持命令的选项补全功能,它依赖于python的argcomplete插件。 1)安装argcomplete: [root@ansible ~]# yum -y install python-argcomplete #或者任何系统都可以使用pip工具安装argcomplete,如下 [root@ansible ~]# pip install argcomplete 2)安装完成后,还需要激活该插件 [root@ansible ~]# bash -version #要求bash版本大于或等于'4.2' GNU bash, 版本 4.2.46(2)-release (x86_64-redhat-linux-gnu) [root@ansible ~]# activate-global-python-argcomplete #激活插件 如果bash版本低于4.2

ansible中的幂等性

心不动则不痛 提交于 2020-01-22 18:55:51
1、ansible中的幂等性 ansible中绝大多数的模块都具有幂等特性,意味着执行依次或多次不会产生副作用。但是shell、command、script、raw这四个模块时不满足幂等性,所有操作会重复执行,但是有些操作不允许重复执行,比如MySQL的初始化命令mysql_install_db,逻辑上它只在第一次配置的过程中初始化依次,其他任何时候都不应该再执行。所有,每当使用这四个模块的时候,都要想一想,重复执行这个命令会不会产生负面影响。 当然,在上面的四个模块中,除了raw模块外,都提供了实现幂等特性的参数,就是creates和removes: creates参数:当指定的文件或目录存在时,则不执行命令; removes参数:当指定的文件或目录不存在时,则不执行命令; 示例如下: --- - name: use some module hosts: node gather_facts: false tasks: # 网卡配置文件不存在时则不执行 - name: use command module command: ifup ens33 args: removes: /etc/sysconfig/network-scripts/ifcfg-ens33 # mysql配置文件已存在时则不执行,避免覆盖 - name: use shell module shell: cp

How to share group_vars between different inventories in Ansible?

人走茶凉 提交于 2020-01-22 09:32:30
问题 The Ansible best practices documentation recommends to separate inventories: inventories/ production/ hosts.ini # inventory file for production servers group_vars/ group1 # here we assign variables to particular groups group2 # "" host_vars/ hostname1 # if systems need specific variables, put them here hostname2 # "" staging/ hosts.ini # inventory file for staging environment group_vars/ group1 # here we assign variables to particular groups group2 # "" host_vars/ stagehost1 # if systems need

Ansible with_items if item is defined

喜夏-厌秋 提交于 2020-01-22 08:30:10
问题 Ansible 1.9.4. The script should execute some task only on hosts where some variable is defined. It works fine normally, but it doesn't work with the with_items statement. - debug: var=symlinks when: symlinks is defined - name: Create other symlinks file: src={{ item.src }} dest={{ item.dest }} state=link with_items: "{{ symlinks }}" when: symlinks is defined But I get: TASK: [app/symlinks | debug var=symlinks] ********************* skipping: [another-host-yet] TASK: [app/symlinks | Create

Add swap memory with ansible

只谈情不闲聊 提交于 2020-01-22 08:27:48
问题 I'm working on a project where having swap memory on my servers is a needed to avoid some python long running processes to go out of memory and realized for the first time that my ubuntu vagrant boxes and AWS ubuntu instances didn't already have one set up. In https://github.com/ansible/ansible/issues/5241 a possible built in solution was discussed but never implemented, so I'm guessing this should be a pretty common task to automatize. How would you set up a file based swap memory with

自动化运维工具 ANSIBLE(一)

会有一股神秘感。 提交于 2020-01-21 20:59:57
本章内容 自动化运维介绍 Ansible主要组成部分 安装 相关文件 主机清单inventory ansible 配置文件 自动化运维介绍 公司计划在年底做一次大型市场促销活动,全面冲刺下交易额,为明年的上市做准备。公司要求各业务组对年底大促做准备,运维部要求所有业务容量进行三倍的扩容,并搭建出多套环境可以共开发和测试人员做测试,运维老大为了在年底有所表现,要求运维部门同学尽快实现,当你接到这个任务时,有没有更快的解决方案? ansible架构 Ansible工作原理 Ansible主要组成部分 ANSIBLE PLAYBOOKS:任务剧本(任务集),编排定义Ansible任务集的配置文件,由Ansible顺序依次执行,通常JSON格式的YML文件 INVENTORY:Ansible管理主机的清单/etc/anaible/hosts MODULES:Ansible执行命令的功能模块,多数为内置核心模块,也可自定义 PLUGINS:模块功能的补充,如连接类型插件、循环插件、变量插件、过滤插件等,该功能不常用 API:供第三方程序调用的应用程序编程接口 ANSIBLE:组合INVENTORY、API、MODULES、PLUGINS的绿框,可以理解为是ansible命令工具,其为核心执行工具 Ansible命令执行来源: USER,普通用户,即SYSTEM ADMINISTRATOR

如何ansible安装lnmp?

假如想象 提交于 2020-01-21 12:36:48
进入vim nginx.yml hosts: webservers tasks: name: “安装LNMP相关组件” yum: name: gcc,pcre-devel,zlib-devel,mysql,mysql-server,php,php-mysql,php-fpm state: latest name: “推送Nginx源码包” unarchive: src: nginx-1.11.2.tar.gz dest: /root/ name: “分发脚本安装nginx” script: lnmp.sh name: “推送配置文件” copy: src: nginx.conf dest: /usr/local/nginx/conf/nginx.conf name: “启动nginx” shell: /usr/local/nginx/sbin/nginx name: “启动MySQL” service: name: mysqld state: started name: “启动php” service: name: php-fpm state: started name: “推送Discusz” unarchive: src: Discuz_X3.3_SC_UTF8.zip dest: /usr/local/nginx/html/ mode: 0777 name: