--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/416c3da4-e9a3-4646-bcd7-42a0bd5e5a44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for the help, Josh.I actually am trying to run a command once on a certain set of EC2 instances I'm managing that match a specific tag. This seems like a very reasonable thing to do and yet the run_once skipping functionality makes this quite difficult. I managed to find two similar but different ways to do this (though not exactly elegant), which I'll post for future reference. I was inspired by https://groups.google.com/forum/#!topic/ansible-project/cpnrBRxLy0E and https://imil.net/blog/2016/08/05/Ansible_and_AWS_ASGMethod 1 (serial 1 is important due to the add_host behavior Josh pointed out). Run the playbook with the AWS dynamic inventory script (-i ec2.py)- hosts: ec2user: ubuntuserial: 1gather_facts: falsetasks:- name: add only nodes that don't match your_tag_name to in-memory host groupadd_host:name: "{{ inventory_hostname }}"groups: your_hostswhen: ec2_tag_Name != your_tag_nameand then run the rest of your playbook not serially and perform run_once actions like this:- hosts: ec2user: ubuntugather_facts: truetasks:- name: Run once on your_tag_nameshell: echo yes >> yes.txtrun_once: truedelegate_to: "{{ groups['your_hosts'][0] }}"Method 2: use the ec2_instance_facts module to create the in-memory group. This requires a tag name variable or constant you can reference to match instances with- hosts: localhostuser: ubuntuconnection: localgather_facts: truetasks:- name: create an in memory group of only nodes with your_tag_nameadd_host:name: "{{ item }}"groups: your_hostswith_items: "{{ ec2.instances | selectattr('state.name', 'equalto', 'running') | selectattr('tags.Name', 'equalto', your_tag_name ) | map(attribute='public_ip_address')|list }}"Either way, if you want to use the information from ec2.py then you'll end up having two hosts sections and some verbosity. I suppose with the ec2_instance_facts one could potentially create groups of EC2 hosts and run the playbook all with hosts: localhost and delegate tasks to certain groups? I haven't tried this as I've spend enough time getting run_once to work for now.Dave
- meta: refresh_inventory
to re-run the inventory script (which should discover newly created EC2 instances).--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d3527123-e6ce-46b3-93c2-579a54cf40b7%40googlegroups.com.