ansible

Ansible and hardware checks

我是研究僧i 提交于 2020-01-07 00:35:30
问题 I have to check different hardware and configurations elements on Linux machines using ansible, and I am not sure at all about how to do it (RAM, disk space, DNS, CPU...), I've understood that I can find nearly all I want in the ansible facts, but I do not understand how I can use it. For example, I have to check if the RAM amount is at least of 4GB and have an alarm if not, so I tried many things, and... nothing works. Here is an example of what I tried. - hosts: client remote_user: user

简单web架构实例应用

♀尐吖头ヾ 提交于 2020-01-06 21:53:37
一、架构图 dns完成解析web1,web2来实现负载均衡 web1,web2使用后台的mysql数据库 web1,web2的页面数据全部放在nfs数据上,实现自动挂载 nfs服务器为web1,web2提供网页数据 10.7.2. 准备工作 设置ip信息 nmcli con add ifname ens33 con-name ens33 type ethernet ipv4.method manual \ ipv4.address 192.158.46.150/24 ipv4.gateway 192.168.46.1 Note 我使用的nmcli修改的ip,当然也是可以手工修改的。 10.7.3. ansible的配置 10.7.3.1. 安装ansible [root@localhost ~]# yum install ansible 10.7.3.2. 添加主机 需要添加如下内容到/etc/ansible/hosts文件中去。 [client] 192.168.46.159 [dns] 192.168.46.158 [web] 192.168.46.157 192.168.46.156 [db] 192.168.46.155 [nfs] 192.168.46.154 [self] 192.168.46.150 10.7.3.3. 配置免密码登陆

ansible hangs in “sudo yum install”' step

☆樱花仙子☆ 提交于 2020-01-06 19:57:13
问题 I am trying to setup ansible (2.0) for installing software on a linux box ies-iesd-jktools is the machine with ansible. ies-iesd-git-06 is the target. User account is iesdgrid that can do sudo on target machine. Following command hangs on remote:- ies-iesd-jktools:~/ansible$ ansible ies-iesd-git-06 \ -i inventory -m raw \ -a "sudo yum install -y python-simplejson" -vvvv Using /usr/src/ansible/ansible.cfg as config file SUDO password: <I type password here> Loaded callback minimal of type

Ansible-基础配置及常用模块

泪湿孤枕 提交于 2020-01-06 15:28:49
一、Ansible介绍 1.1、什么是ansible? Ansible是一个配置管理系统configuration management system, python 语言是运维人员必须会的语言, ansible 是一个基于python 开发的自动化运维工具, 其功能实现 基于ssh远程连接服务 , ansible 可以实现 批量系统配置,批量软件部署,批量文件拷贝,批量运行命令 等功能, 除了ansible之外,还有saltstack 等批量管理软件. 1.2、软件特点 1)ansible不需要单独安装客户端,SSH相当于ansible客户端。 2)ansible不需要启动任何服务,仅需安装对应工具即可。 3)ansible依赖大量的python模块来实现批量管理。 4)ansible配置文件 /etc/ansible/ansible.cfg 。 5)Ansible是一种agentless(基于ssh),可实现批量配置、命令执行和控制,基于Python实现的自动化运维工具。Ansible的两个特性: 模块化 :通过调用相关模块,完成指定任务,且支持任何语言编写的自定义模块; playbook :剧本,可根据需要一次执行完剧本中的所有任务或某些任务; 1.3、架构特点 1)连接插件(connectior plugins) :用于连接主机 用来连接被管理端。 2)核心模块(core

ansible, command module and jq with pipe

非 Y 不嫁゛ 提交于 2020-01-06 14:33:32
问题 I'm trying to run a docker command that returns a list of containers, and their size. The command is docker container ls --format "{\"name\":\"{{.Names}}\", \"size\":\"{{.Size}}\"} " --all | jq --slurp When I try to run this in an Ansible playbook it explodes: - name: Get cointainer size raw: /path/to/script/docker-cointainer-size.sh The truncated error is: fatal: [localhost]: FAILED! => changed=true msg: non-zero return code rc: 2 stderr: |- jq - commandline JSON processor [version 1.5-1

Ansible: Detect if a Linux filesystem is mounted read-only

偶尔善良 提交于 2020-01-06 12:41:16
问题 I'm trying to detect if a particular filesystem is mounted read-only or read-write on Linux (Ubuntu 16.04). Using the stat module won't work because it always returns the posix permissions regardless of the actual ability to write into the directory. I'm able to accomplish this with the rather intrusive and cumbersome code below, which attempts to create a dot file. I'd appreciate a cleaner and more elegant alternative, that can also detect if the directory is not a mount point (which would

How to use return values of one task in another task for a different host in ansible

岁酱吖の 提交于 2020-01-06 08:16:26
问题 I was trying to setup mysql master slave replication with ansible for a hostgroup consisting of 2 mysql hosts. Here is my scenario: I run one task in the 1st host and skips the 2nd host, so the 1st task (i.e master replication status) returns some values like Position, File etc. Then, I run another task in 2nd host (skips the 1st hosts), This task uses the return values of the 1st task like master.Position, master.File etc. Now, when I run the playbook, the variables of the 1st task does not

How to use return values of one task in another task for a different host in ansible

浪尽此生 提交于 2020-01-06 08:14:25
问题 I was trying to setup mysql master slave replication with ansible for a hostgroup consisting of 2 mysql hosts. Here is my scenario: I run one task in the 1st host and skips the 2nd host, so the 1st task (i.e master replication status) returns some values like Position, File etc. Then, I run another task in 2nd host (skips the 1st hosts), This task uses the return values of the 1st task like master.Position, master.File etc. Now, when I run the playbook, the variables of the 1st task does not

Ansible: Attach role to user in postgres

妖精的绣舞 提交于 2020-01-06 08:06:27
问题 I am already having a role in Postgres namely readonly . It has readonly access on all the tables in all the databases. I want to attach this role to a user so that he/she also gets the readonly access on all tables in one command. How can I perform the following command using ansible's postgresql_user module? mydb=> grant readonly to dev_username; EDIT: adding more details This is what I have tried, - name: Postgres postgresql_user: login_host: xx.xx.com login_password: mypassword login_user

how to set ansible conditinal search

自作多情 提交于 2020-01-06 08:03:21
问题 I am trying to extract few values from a task out put. please see my playbook sample - name: Iterate JSON set_fact: app_item: "{{ item.name }}" when: "{{ result.results|json_query('[].\"scope member\"[?\"vdom\"==`\"vdom-shop\"`].vdom')|flatten|first }} == vdom-shop" with_items: "{{ result.results }}" please see the json output from the previous task { "msg": { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "failed": false, "msg": "Custom Query