ansible

use conditionals in vars ansible [duplicate]

十年热恋 提交于 2020-02-25 09:45:46
问题 This question already has an answer here : How can I use a condition to set a variable value in Ansible? (1 answer) Closed 2 years ago . Can we use conditionals in "vars:" section of a playbook, I am aware of set_fact in tasks ,but I want to know we could use in section like below: --- - hosts: "{{ host1 }}" vars: var1: "{{ passed_var1 }}" var2: "<conditionally assign value based on {{ var1 }}" 回答1: You can do something like: --- - name: Test Play hosts: local gather_facts: false vars: var1:

Ansible-随笔-7

一笑奈何 提交于 2020-02-23 12:55:57
扩展Ansible的插件系统。 有的时候,如果Ansible内置的插件无法满足需求时,我们可以自己编写新插件。 以下情况下可以考虑开发新插件: 1、除Paramiko、本机SSH、Local、Winrm等连接方式外,希望Ansible基于新的通信方式与远程主机交互。 2、除内置的with_items、with_fileglob循环体外,希望有新的遍历方式。 3、除内置的host_vars、group_vars等变量调用方式外,希望有新的变量定义方式。 4、除内置的jinja2渲染模板、to_yaml、to_json等过滤器,希望有新的过滤器。 5、定义新的回调机制,捕获响应事件后自定义新的响应形式。 对stdout输出结果做处理; 增加日志记录,如插入到mysql、redis、mongodb; 增加事件响应方式,比如playbook返回success时,发送邮件到各部门。 插件存放位置: 从github上下载插件模板(可以下载action插件、callback插件、connection插件等)到上面对应的目录中,然后 进行相应的修改即可。 举例:编写过滤插件deal_list_num.py /usr/share/ansible/plugins/filter/deal_list_num.py 后续需要模仿着这个来写。这里的data是 | 符号前面的数字。 num_list |

Ansible基本介绍

六月ゝ 毕业季﹏ 提交于 2020-02-23 03:18:15
前言 2020年2月23号晚上,闲的蛋疼,想着复习整理一下ansible吧。。。 工具介绍 Ansible是一款自动化运维工具,旨在降低人为失误,提高业务的自动化及工作效率。常用作软件自动化部署、自动化配置、自动化管理、系统化任务、持续继承、平滑升级等等。创始人是Michael DeHaan。 资料查阅 官方地址:https://www.ansible.com/ 官方文档:https://docs.ansible.com/ 中文文档:http://www.ansible.com.cn/ 代码仓库:https://github.com/ansible/ansible 版本蓝图:https://docs.ansible.com/ansible/latest/roadmap/index.html(不过2.0以前的版本都被淘汰了,最原始的版本是0.0.1版本,发布与2012年3月9日) 同类型工具 Chef、Fabric、Puppet、SaltStack Ansible优点 Ansible是采用python进行开发的 Ansible包含丰富的内置模块,并且在持续不断的更新 Ansible采用去中心化的思想,即不需要客户端 Ansible的工作原理 Ansible工具通过调用各种内置的应用模块将指令推送指被管理端进行执行,并在执行完毕之后自动删除产生的临时文件

Using --become for ansible_connection=local

你说的曾经没有我的故事 提交于 2020-02-21 15:21:13
问题 With a personal user account (userx) I run the ansible playbook on all my specified hosts. In ansible.cfg the remote user (which can become root) to be used is: remote_user = ansible For the remote hosts this all works fine. It connects as the user Ansible, and executes all tasks as wished for, also changing information (like /etc/ssh/sshd_config ) which requires root rights. But now I also want to execute the playbook on the Ansible host itself. I put the following in my inventory file:

Using --become for ansible_connection=local

痞子三分冷 提交于 2020-02-21 15:12:22
问题 With a personal user account (userx) I run the ansible playbook on all my specified hosts. In ansible.cfg the remote user (which can become root) to be used is: remote_user = ansible For the remote hosts this all works fine. It connects as the user Ansible, and executes all tasks as wished for, also changing information (like /etc/ssh/sshd_config ) which requires root rights. But now I also want to execute the playbook on the Ansible host itself. I put the following in my inventory file:

本人的第一个博客

家住魔仙堡 提交于 2020-02-21 08:00:05
hello world 个人运维技能必备 语言: Python、Shell 系统: Linux、Windows 数据库: Mysql、Redis、MongoDB MySQL代理: Mycat、Altas、Cobar 版本管理: Git 高可用/负载均衡 LVS、Nginx、HAProxy、Keepalived 批量管理: Ansible、Saltstack 装机: Kickstart、Cobbler 容器/虚拟化: Docker、KVM、VM 持续集成: Jenkins 日志: ELK Stack 监控: Zabbix、Promentheus、Grafana、告警平台、Drools监控 分布式: Ceph、GlusterFS、FastDFS web: Nginx、Tomcat、Apache 抓包分析: Tcpdump、Wireshark 同步备份: Rsync 来源: https://www.cnblogs.com/small-wei/p/10825972.html

Ansible - Play with hosts in order I desire

怎甘沉沦 提交于 2020-02-20 07:56:46
问题 When running a playbook Ansible randomly sets a node as first, second and third. TASK [setup] ******** ok: [node-p02] ok: [node-p03] ok: [node-p01] How can I configure Ansible to ensure it plays as: TASK [setup] ******** ok: [node-p01] ok: [node-p02] ok: [node-p03] Serial: 1 is not an option, since it slows down the play, and my playbook is meant for 3 nodes in a single play. 回答1: Applicable for Ansible 2.4 and higher: This is now the default behaviour, ansible will play the hosts in the

Ansible-使用playbook自动化部署mariadb

允我心安 提交于 2020-02-19 14:29:50
1,编写mariadb.yaml文件 [root@c7-4-mh02 ansible]# vim mariadb.yaml--- - hosts: mariadb remote_user: root tasks: - name: install mariadb yum: name=mariadb-server state=present - name: start mariadb service: name=mariadb state=restarted enabled=true 2,检查mariadb.yaml文件语法是否正确 # 检查语法是否正确 ansible-playbook --syntax-check mariadb.yaml # 执行mariadb.yaml文件,安装并启动mariadb ansible-playbook mariadb.yaml # 查看mariadb是否启动 systemctl status mariadb 来源: https://www.cnblogs.com/HsLM/p/12331096.html

How can I get a list of hosts from an Ansible inventory file?

白昼怎懂夜的黑 提交于 2020-02-19 09:39:40
问题 Is there a way to use the Ansible Python API to get a list of hosts from a given inventory file / group combination? For example, our inventory files are split up by service type: [dev:children] dev_a dev_b [dev_a] my.host.int.abc.com [dev_b] my.host.int.xyz.com [prod:children] prod_a prod_b [prod_a] my.host.abc.com [prod_b] my.host.xyz.com Can I use ansible.inventory in some way to pass in a specific inventory file, and the group I want to act on, and have it return a list of hosts that

ansible基础-roles

穿精又带淫゛_ 提交于 2020-02-17 18:27:40
一 简介 注:本文demo使用ansible2.7稳定版 在我看来,role是task文件、变量文件、handlers文件的集合体,这个集合体的显著特点是: 可移植性和可重复执行性。 实践中,通常我们以 部署某个服务 为单元作为一个role ,然后将这些服务单元(role)放在一个roles目录下。主playbook文件通过调用roles目录下的role,来实现各种灵活多变的部署需求。 本节主要为大家介绍下roles的目录结构、引用方法及其他特性。 二 创建与目录结构 2.1 创建roles 通常创建一个role的方法有两种: 命令mkdir和touch行手动创建 使用ansible-galaxy自动初始化一个role 命令行手动创建方式就无需多说了,即需要哪个目录和文件就用「mkdir」和「touch」命令创建出来。 我个人比较喜欢使用「ansible-galaxy」命令创建,创建完后再删除我不需要的目录,这样可以避免因手误创建出错的问题。 例如,我想使用「ansible-galaxy init」命令创建一个名字为role_A 的role,可以这样写: ➜ lab-ansible ansible-galaxy init role_A - role_A was created successfully 创建后的目录结构如下: ➜ lab-ansible tree role_A