【发布时间】:2019-05-28 16:41:08
【问题描述】:
我有一个 Ansible 配置,我正在其中创建一个 EC2 实例。实例准备好后,我想禁用定期 apt 更新并等待当前更新过程完成。每当我在 yml 文件中添加配置时,它都会在我的本地系统上执行命令。我做错了什么?
yml 文件:
---
- name: Provision an EC2 Instance
hosts: localhost
connection: local
gather_facts: False
tags: provisioning
tasks:
- name: Create New security group with below given name
local_action:
module: ec2_group
name: "{{ security_group }}"
description: Security Group for Newly Created EC2 Instance
region: "{{ region }}"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
rules_egress:
- proto: all
cidr_ip: 0.0.0.0/0
- name: Launch the new t2 micro EC2 Instance
local_action: ec2
group={{ security_group }}
instance_type={{ instance_type}}
image={{ image }}
wait=true
region={{ region }}
keypair={{ keypair }}
count={{count}}
register: ec2
现在,在此之后,我等待 ssh 完成并希望在新创建的 Ec2 实例上传递以下命令:
- name: Disable timers for unattended upgrade, so that none will be triggered by the `date -s` call.
raw: systemctl disable --now {{item}}
with_items:
- 'apt-daily.timer'
- 'apt-daily-upgrade.timer'
- name: Reload systemctl daemon to apply the new changes
raw: systemctl daemon-reload
- name: Purge autoupdate
raw: apt -y purge unattended-upgrades
- name: Update apt cache
raw: apt -y update
但是将它们添加为 raw 不起作用,甚至将它们添加为命令。
【问题讨论】:
标签: amazon-web-services amazon-ec2 ansible