From the ansible docs the ec2 module (http://docs.ansible.com/ec2_module.html) mentions a user_data field. However, there is no example showing the use of user_data.--
I've tried a variety of things to pass through to the user field to no avail including
user_data: file.txt
user_data: "{{ lookup('file', file.txt') }}"
user_data: """#!/bin/bash
apt-get update
apt-get install htop"""
And variations thereof. My googlefu has failed me so far to find any results for how to solve this issue.
Thanks if you have any input.
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/64b86c47-036a-471f-8a64-9cbd38c04f5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
ERROR: Syntax Error while loading YAML script, /etc/ansible/playbooks/search/roles/aws/tasks/main.yml
Note: The error may actually appear before this position: line 13, column 17
state: running
user_data: """#!/bin/bash
^
This one looks easy to fix. It seems that there is a value started
with a quote, and the YAML parser is expecting to see the line ended
with the same kind of quote. For instance:
when: "ok" in result.stdout
Could be written as:
when: '"ok" in result.stdout'
or equivalently:
when: "'ok' in result.stdout"
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a1c6540e-6ece-49b8-84f8-83802cb97ebb%40googlegroups.com.
- ec2:aws_access_key: '{{ aws_access_key }}'aws_secret_key: '{{ aws_secret_key }}'region: '{{ win_ec2_region }}'instance_type: '{{ win_ec2_instance_type }}'instance_tags:Name: '{{win_ec2_name_prefix}}-{{item.name}}'group: '{{ win_ec2_security_group }}'key_name: '{{ win_ec2_key_name }}'image: '{{ item.id }}'user_data: "{{ lookup('file', 'win_ec2_user_data') }}"exact_count: 1count_tag:Name: '{{win_ec2_name_prefix}}-{{item.name}}'wait: yeswith_items: win_ec2_imagesregister: win_ec2
<powershell>iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'))</powershell>
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgyG79kBFTw3O_i62_FTd7MeBtuvLWUNnEauFLfNkQw66w%40mail.gmail.com.
- name: wait for instances to listen on port 5986 (winrm https)wait_for:state=startedhost={{ item.tagged_instances[0].public_ip }}port=5986with_items: win_ec2.resultswhen: win_ec2_images and win_ec2 is defined- name: obtain windows passwords for instancesec2_win_pass:
aws_access_key: '{{ aws_access_key }}'aws_secret_key: '{{ aws_secret_key }}'region: '{{ win_ec2_region }}'
instance_id: "{{ item.tagged_instances[0].id }}"private_key: "{{ lookup('file', win_ec2_private_key) }}"with_items: win_ec2.resultsregister: win_ec2_passwordswhen: win_ec2_images and win_ec2 is defined- name: add_hostadd_host:name: '{{ item.item.tagged_instances[0].public_dns_name }}'groups: 'cloud,ec2,windows,{{win_ec2_name_prefix}}-{{ item.item.item.name }}'ansible_ssh_host: '{{ item.item.tagged_instances[0].public_ip }}'ansible_ssh_port: 5986ansible_ssh_user: '{{ item.item.item.user }}'ansible_ssh_pass: '{{ item.password }}'ansible_connection: 'winrm'with_items: win_ec2_passwords.resultswhen: win_ec2_images and win_ec2_passwords is defined
- name: ping new windows instanceshosts: windowsgather_facts: falsetasks:- action: win_ping
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3960ea12-56fa-4ee1-a902-6c090ea72ae0%40googlegroups.com.
The file lookup plugin is your friend.
On Saturday, 25 October 2014 20:33:32 UTC+1, Chris Church wrote:The file lookup plugin is your friend.It is – if one wishes to supply text-based user data. Unfortunately, I have a requirement to provide a binary blob of user data, and the file lookup plugin does not seem to handle that – looking at the source code, it expects the file to be a UTF8-encoded text file.
<snip>
- local_action: slurp src="{{role_path}}/files/ec2_user_data"register: ec2_user_data_b64- ec2:user_data_b64: '{{ ec2_user_data_b64.content }}'...
--
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/9708972a-8a15-4819-9837-4a172b9cf608%40googlegroups.com.
user_data: |
#!/bin/bash
echo "Defaults:{{admin_user}} !requiretty" > /etc/sudoers.d/disable_requiretty
# Join multiple lines without new line
value: >
part 1
part 2
# Join with newline
value2: |
line 1
line 2
# fetch http://169.254.169.254/latest/user-data
# cat user-data
/Td6WFoAAATm1rRGAgAhARYAAAB … /sCAAAAAARZWg==
# base64 -d user-data test.tar.xz
# tar tvf test.tar.xz
-rw-r--r-- 0 djn staff 2 Dec 26 10:40 1.txt
-rw-r--r-- 0 djn staff 2 Dec 26 10:40 2.txt
-rw-r--r-- 0 djn staff 322 Dec 24 12:03 configinit
Yaml has a notation for multiline string. I set user data like so:
user_data: |
#!/bin/bash
echo "Defaults:{{admin_user}} !requiretty" > /etc/sudoers.d/disable_requiretty
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a876f870-7867-4bc7-b20e-10175ee9659en%40googlegroups.com.