facter

Ansible Playbook 使用条件判断语句

試著忘記壹切 提交于 2021-01-23 21:04:02
先介绍一下 gather_facts 参数,该参数用于指定在执行任务前,是否先执行 setup 模块获取主机相关信息,以便给后面的任务使用 [root@localhost ~] # ansible 192.168.119.134 -m setup # 查看主机的facter信息 192.168.119.134 | SUCCESS => { " ansible_facts " : { " ansible_all_ipv4_addresses " : [ " 192.168.119.134 " ...... 条件判断语句写法: [root@localhost ~ ]$ cat when.yml --- - hosts: 192.168.119.134 user: root gather_facts: True # 必须先开启这个 tasks: - name: use when shell: touch /tmp/ when.txt when: ansible_date_time.year == " 2019 " # 表示当 ansible_date_time.year 的值等于 2019 时,就使用 shell 模块执行 touch /tmp/when.txt 命令 来源: oschina 链接: https://my.oschina.net/u/4329213/blog

《Ansible自动化运维:技术与最佳实践》第三章读书笔记

纵然是瞬间 提交于 2021-01-02 11:08:48
Ansible 组件介绍 本章主要通过对 Ansible 经常使用的组件进行讲解,使对 Ansible 有一个更全面的了解,主要包含以下内容: Ansible Inventory Ansible Ad-Hoc 命令 Ansible playbook Ansible facts Ansible role Ansible Galaxy Ansible Inventory Inventory 组件主要存储在配置管理工作中需要管理的不同业务的不同机器的信息。默认 Ansible 的 Inventory 是静态的 INI 格式的文件 /etc/ansible/hosts ,可以通过 ANSIBLE_HOSTS 环境变量指定或者运行 ansible 和 ansible-playbook 的时候用 -i 参数临时设置。 定义主机和主机组 首先看下默认 Inventory 文件是如何定义主机和主机组的,默认的 Inventory 文件如下: # - 主机组由[header]元素分隔 # - 您可以输入主机名或IP地址 # - hostname/ip 可以是多个组的成员 # 未组合的主机,在任何主机组之前指定。 ## green.example.com ## blue.example.com ## 192.168.100.1 ## 192.168.100.10 # 属于'webservers

puppet部署及应用

北城余情 提交于 2020-08-13 16:07:27
简介 puppet是一种Linux、Unix、windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet的设计目标是简化对这些资源的管理以及妥善处理资源间的依赖关系。 puppet采用C/S星状的结构,所有的客户端和一个或几个服务器交互。每个客户端周期的(默认半个小时)向服务器发送请求,获得其最新的配置信息,保证和该配置信息同步。每个puppet客户端每半小时(可以设置)连接一次服务器端, 下载最新的配置文件,并且严格按照配置文件来配置客户端. 配置完成以后,puppet客户端可以反馈给服务器端一个消息. 如果出错,也会给服务器端反馈一个消息。 工作流程 puppet客户端首先会连接到puppet服务器端,并且通过facter工具把客户端的基本配置信息发送给服务器端. 服务器端通过分析客户端的主机名,通过node 定义,找到该主机的配置代码,然后编译配置代码,把编译好的配置代码发回客户端,客户端执行代码完成配置.并且把代码执行情况反馈给puppet服务器端. 常用资源 常见的资源有notify(调试与输出),file(配置文件),package(软件安装),service(服务管理),exec(执行命令),cron(定时脚本),user(用户),group(用户组)

How can I create a custom :host_role fact from the hostname?

ぃ、小莉子 提交于 2020-05-31 04:08:08
问题 I'm looking to create a role based on host name prefix and I'm running into some problems. Ruby is new to me and although I've done extensive searching for a solution, I'm still confused. Host names look like this: work-server-01 home-server-01 Here's what I've written: require 'facter' Facter.add('host_role') do setcode do hostname_array = Facter.value(:hostname).split('-') first_in_array = hostname_array.first first_in_array.each do |x| if x =~ /^(home|work)/ role = '"#{x}" server' end role

Puppet 的部署与应用,看这一篇就够了

巧了我就是萌 提交于 2020-03-01 10:53:17
工作原理 Puppet的目的是让管理员只集中于要管理的目标,而忽略实现的细节。Puppet既可以在单机上使用,也可以c/s使用,在大规模使用puppet的情况下,通常使用c/s结构,在这种结构中puppet客户端只运行puppetclient,puppet服务器只运行puppetmaster。 工作流程 1)客户端puppet调用facter(facter是通过ssl加密收集及检测分析客户端配置信息的一个工具),facter探测出主机的一些变量,如主机名,内存大小,ip地址等。Puppet把这些信息通过ssl连接发送到服务器器端 2)服务器端的puppetmaster通过facter工具分析检测客户端的主机名,然后找到项目主配置文件mainfest里面对应的node配置,并对该部分内容进行解析。Facter发送过来的信息可以作为变量处理,node牵扯到的代码才解析,其他没牵涉的代码不解析,解析分为几个阶段,首先进行语法检查,如果语法没错,就继续解析,解析的结果生成一个中间的“伪代码”,然后把伪代码发送给客户端。 3)客户端接收到伪代码,并执行,客户端把执行的结果发送给服务器。 4)服务器把客户端的执行结果写入日志。 Puppet工作过程有以下两点值得注意: 1)为了保证安全,client和master之间是基于ssl和证书的

Puppet/Facter “Could not retrieve fact fqdn”: How to fix or circumvent?

房东的猫 提交于 2019-12-18 10:27:18
问题 I'm learning about puppet and trying to experiment with it on a VM at home. I'm not using a puppet server yet, just running things locally. It works okay, but every time I run puppet apply ... , I get a delay of several seconds, after which it displays the message warning: Could not retrieve fact fqdn I assume the message is linked to the delay, and I want to get rid of it (the delay--I can live with the message). Googling for a solution seems to indicate that it's somehow related to DNS

Puppet/Facter “Could not retrieve fact fqdn”: How to fix or circumvent?

回眸只為那壹抹淺笑 提交于 2019-12-18 10:27:13
问题 I'm learning about puppet and trying to experiment with it on a VM at home. I'm not using a puppet server yet, just running things locally. It works okay, but every time I run puppet apply ... , I get a delay of several seconds, after which it displays the message warning: Could not retrieve fact fqdn I assume the message is linked to the delay, and I want to get rid of it (the delay--I can live with the message). Googling for a solution seems to indicate that it's somehow related to DNS

Unable to use $facts as a hash in the puppet manifest

醉酒当歌 提交于 2019-12-12 05:09:33
问题 Here is the manifest code which is failing: each( $facts['partitions'] ) |$name, $device| { notice( "${facts['hostname']} has device ${name} with size ${device['size']}" ) } The error: [manifests]$puppet apply /vagrant/manifests/mountpoints.pp Error: Evaluation Error: Operator '[]' is not applicable to an Undef Value. at /vagrant/manifests/mountpoints.pp:1:7 on node siy Error: Evaluation Error: Operator '[]' is not applicable to an Undef Value. at /vagrant/manifests/mountpoints.pp:1:7 on node

Configure remote rulesets with Puppet

送分小仙女□ 提交于 2019-12-10 11:29:12
问题 I'm trying to automate the Prometheus node_exporter and my Prometheus Server. For the node_exporter I've written a module to install all the needed packages, set the $::ipaddress based on facter and some more.. Now I'd like to make sure that the collected informations ( $hostname , $job_name , [...]) from the applying node are exported into the respective remote Prometheus configfile, but I want to have this step done asynchronously, so for example with a puppet agent run afterwards on the

Puppet/Facter “Could not retrieve fact fqdn”: How to fix or circumvent?

依然范特西╮ 提交于 2019-11-29 21:15:38
I'm learning about puppet and trying to experiment with it on a VM at home. I'm not using a puppet server yet, just running things locally. It works okay, but every time I run puppet apply ... , I get a delay of several seconds, after which it displays the message warning: Could not retrieve fact fqdn I assume the message is linked to the delay, and I want to get rid of it (the delay--I can live with the message). Googling for a solution seems to indicate that it's somehow related to DNS lookups, but I can't really find anything else about it, which seems surprising. All I want is to be able