1

I have a requirement where I have to install AWS SSM Agent on multiple EC2 instances(of different flavors) using Ansible. Can someone please help me? or Suggest me how to achieve this?

I wrote the following script and tried. It is working but, is there a way to achieve this using "Package" module? Because I am afraid my approach might do a reinstall (even if it is already installed). Thanks in advance.

(OR)

Do you think it is better to use Shell commands (https://aws.amazon.com/premiumsupport/knowledge-center/install-ssm-agent-ec2-linux/) in the Ansible script to install the agent and refer to them based on the condition of os flavour?

---
- 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"
ram n
  • 49
  • 6
  • 3
    Hi, I think you need to look for information internet first, the right way to do questions here is try to be the best specific as possible. For example I dont know if you know how to use ansible, do you know how to write ansible scriptitng? There is an option to switch installation depending on the operative system version you can use is to install the agent on different S.O EC2 Flavors. Do you need an example? when: ansible_os_family == "Ubuntu". Please read this to improve the way to do questions -> http://www.catb.org/~esr/faqs/smart-questions.html – Raul Hugo May 14 '20 at 17:23
  • Can you post something you have already tried? Like a playbook? Try it out first and if you are stuck and getting errors, then post it here. – saurabh14292 May 15 '20 at 06:48
  • Hello Raul Hugo and Saurabh. Thanks for your reply. Yes I have a basic knowledge of writing and executing Ansible scripts. Please find above my edited content. – ram n May 17 '20 at 00:27

0 Answers0