amazon-web-services - 'ansible_date_time' 未定义

标签 amazon-web-services amazon-ec2 ansible ansible-playbook

尝试使用 Ansible 的 ec2_ami 模块在 AWS 中注册一个 ec2 实例,并使用当前日期/时间作为版本(我们将来最终会制作很多 AMI)。

这就是我所拥有的:

- name: Create new AMI
  hosts: localhost
  connection: local
  gather_facts: false
  vars:
  tasks:
    - include_vars: ami_vars.yml
    - debug: var=ansible_date_time
    - name: Register ec2 instance as AMI
      ec2_ami: aws_access_key={{ ec2_access_key }}
               aws_secret_key={{ ec2_secret_key }}
               instance_id={{ temp_instance.instance_ids[0] }}
               region={{ region }}
               wait=yes
               name={{ ami_name }}
      with_items: temp_instance
      register: new_ami

来自 ami_vars.yml:
ami_version: "{{ ansible_date_time.iso8601 }}"
ami_name: ami_test_{{ ami_version }}

当我运行完整的剧本时,我收到以下错误消息:
fatal: [localhost]: FAILED! => {"failed": true, "msg": "ERROR! ERROR! ERROR! 'ansible_date_time' is undefined"}

但是,当从单独的剧本单独运行调试命令时,它可以正常工作:
- name: Test date-time lookup
  hosts: localhost
  connection: local
  tasks:
    - include_vars: ami_vars.yml
    - debug: msg="ami version is {{ ami_version }}"
    - debug: msg="ami name is {{ ami_name }}"

结果:
TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "ami version is 2016-02-05T19:32:24Z"
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "ami name is ami_test_2016-02-05T19:32:24Z"
}

知道发生了什么吗?

最佳答案

删除这个:

  gather_facts: false
ansible_date_time是事实的一部分,你没有收集它。

关于amazon-web-services - 'ansible_date_time' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35232088/

相关文章:

apache - "Main Not Found"启动 Apache Geronimo

正则表达式匹配 JCL 工作卡或整张卡的最后一行

linux - 在 WSL 2 上使用 Ansible 通过 snap 安装 microk8s

amazon-web-services - 将子域添加到 Route 53 并从 Route 53 控制该子域下的所有子域

amazon-web-services - 使用非标准分隔符粘合 CSV 的自定义分类器

node.js - 使用 AWS Lambda NodeJS 时无法返回结果

ios - AWS s3 - 在 iOS 中删除多个对象

amazon-web-services - 如何让traefik在我的云架构上工作?

.htaccess - htaccess 重定向到 https 浏览器差异

amazon-web-services - 使用 Ansible 向 AWS 安全组添加和删除多个 IP 地址