我有一个要求,我必须使用 Ansible 在多个 EC2 实例(不同风格)上安装 AWS SSM 代理。有人可以帮帮我吗?或建议我如何实现这一目标?
我编写了以下脚本并尝试了。它正在工作,但是有没有办法使用“包”模块来实现这一点?因为我担心我的方法可能会重新安装(即使它已经安装)。提前致谢。
(或者)
您认为在 Ansible 脚本中使用 Shell 命令(https://aws.amazon.com/premiumsupport/knowledge-center/install-ssm-agent-ec2-linux/)安装代理并参考它们更好吗基于 os 风味的条件?
---
- hosts: all
remote_user: ansible
become: true
tasks:
- name: install SSM if REDHAT
command: "{{ item }}"
loop:
- sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
- sudo systemctl enable amazon-ssm-agent
- sudo systemctl start amazon-ssm-agent
when: ansible_os_family == "RedHat"
- name: install SSM if UBUNTU
command: "{{ item }}"
loop:
- sudo snap install amazon-ssm-agent --classic
- sudo systemctl start snap.amazon-ssm-agent.amazon-ssm-agent.service
when: ansible_os_family == "Debian"