这是我写的Ansible攻略的一部分。
- name: Check OS Version
fail:
msg: "{{ ansible_distribution }} {{ ansible_distribution_version }} is not compatible with this role"
when: ansible_distribution != 'Ubuntu' and ansible_distribution_release != 'trusty'
我在一台ubuntu/trusty的Vagrant机器上运行
我在when语句中使用ansible_hostname变量在命令stdout中查找包含它的字符串,如下所示: when: result.stdout.find("some stdout text {{ansible_hostname}}") == -1 或 when: result.stdout.find("some stdout text {{ansible_hostname}}") != -1 我的任务按预期工作,但ansible在when语句中抛出了有关使用jinja2模板的警告: [WARNING]: when statements should no
我需要创建一个与这里解释的非常类似的检查:Ansible to check diskspace for mounts mentioned as variable 除非我只需要指定的路径(例如/var)。 {{ ansible_mounts }}是一个字典数组,每个字典都包含作为实际路径的变量mount。只有当mount等于某个值时,我才需要在循环中对{{ ansible_mounts }}中的所有项执行检查。 下面是我想用伪代码实现的示例: foreach (mountpoint in ansible_mounts)
{
if (mountpoint["mount"]
我使用Ansible来自动安装、配置和部署使用JBOSS的应用服务器,因此我需要使用内置的jboss来部署包。
这个Ansible任务实际上是运行的最后一个阶段,它只需要检查一个部署是否已经存在,如果已经存在,那么卸载它并重新部署它(成为幂等的)。
在服务器上手动运行以下命令并在每个命令按预期工作后检查返回代码,Ansible中的某个地方拒绝正确读取返回代码!
# BLAZE RMA DEPLOYMENT
- name: Check if Blaze RMA has been assigned to dm-server-group from a previous Ansible run
s
我有一个Jinja2模板,作为使用Ansible对服务器进行修补的电子邮件帖子的一部分。在它中,我有一个if语句,它应该验证快照是否被捕获。下面是游戏手册中设置要评估的变量的部分:
- name: Was a snapshot taken
set_fact:
snapshot: "{{ 'yes' if (snap_result is changed and snap_result is not failed) else 'no'}}"
下面是模板:
******************************************
我有以下几点,其中包括一位同事在老角色中的内容。
---
- name: deploy
include: deploy.yml
when: deploy is defined and deploy == 'True'
- name: undeploy
include: undeploy.yml
when: undeploy is defined and undeploy == 'True'
- name: database-migrate
include: database-migrate.yml
when: db is defin
我正在写一个剧本,应该只运行时,一个新的软件包版本的软件是可用的。这两个版本号都是我用"set_fact“设置的自定义事实 Ansible让你比较版本号,所以我试着这样做: - name: compare versions
debug:
msg: "The version {{ new_version }} is newer than the old version {{ old_version }}"
when: "{{ new_version is version('{{ old_version }}', '>
我正在尝试编写一个剧本,它将从一个组vars文件中加载vars,然后检查是否存在一个变量
我的剧本是这样的:
---
- hosts: "{{ target }}"
roles:
- app
tasks:
- name: alert if variable does not exist
fail:
msg: "{{ item }} is not defined"
when: "{{ item }}" is not defined
with_items:
- country