Hi
I’m trying to install mdatp using this .yml which is run via a .sh where the variables come from.
The problem is I don’t succeed in using the delegate_to: all (so I can run on all the instances under the account)
I basically querry the instance_ids, the account number and using these I have to run the mdatp edr tag set command
I tried also creating an ansible group with all the EC2 instances in the account but didn’t get anywhere.
I want to mention also that the item.tags.Name from AWS are different from my ansible host inventory
- name: Retrieve and tag EC2 instances
hosts: localhost
gather_facts: no
#become: yes
vars_files:
- vars.yml
tasks:
- name: "Get EC2 instance ID - {{ec2_instance}}"
ec2_instance_info:
profile: "{{aws_profile}}"
region: "{{region}}"
filters:
"instance-state-name": [ "running" ]
register: output
- debug: var=output
- set_fact:
ec2_instance: "{{ output.instances | map(attribute='instance_id') | list }}"
- debug: var=ec2_instance
- name: Run mdatp edr tag set on each EC2 instance
ansible.builtin.shell: |
if command -v mdatp &>/dev/null; then
mdatp edr tag set --name GROUP --value "MY-AWS-TAG - {{ item.instance_id }} - {{ aws_profile_number }}"
echo "Tag set for {{ item.instance_id }} " >> /tmp/mdatp_success.txt
else
echo "mdatp is not installed on instance {{ item.instance_id }} " >> /tmp/mdatp_output_error.txt
fi
loop: "{{ output.instances }}"
when:
- item.state.name == 'running'
- item.tags.Name is defined
- "'master' not in item.tags.Name"
- "'nodes' not in item.tags.Name"
- "'prometheus' not in item.tags.Name"
- "'octo' not in item.tags.Name"
- "'eks' not in item.tags.Name"
- "'tc' not in item.tags.Name"
- "'om-' not in item.tags.Name"
delegate_to: all