User-data script syntax error in line 86 when script has 75 lines

http://debugs.theforeman.org/foreman-debug-asEiW.tar.xz

problem i am having is that i use a user data script with 75 lines and the error i am getting is

*Unable to save *
- Render user data template for cesar-steere.1000.local task failed with the following error: ERF22-1307 [Foreman::Renderer::SyntaxError]: Syntax error occurred while parsing the template Unnamed, make sure you have all ERB tags properly closed and the Ruby syntax is valid. The Ruby error: (string):86 :: parse error on value "<" (tLT)
while creating a new host.

i hope that 86 means the line number?!

the script is pretty much standart and the erb ruby syntax check is ok and preview check in foreman too.


··· ----

<%#
kind: user_data
name: Katello Kickstart default user data
oses:
- CentOS 6
- CentOS 7
- Fedora 19
- Fedora 20
- Fedora 21
- Fedora 22
- Fedora 23
-%>
#cloud-config
hostname: <%= @host.shortname %>
fqdn: <%= @host %>
manage_etc_hosts: true

groups:
- admin

users:
- default
- name: admin
   primary-group: admin
   groups: users
   shell: /bin/bash
   sudo: ['ALL=(ALL) ALL']
   lock-passwd: false
   passwd: <%= @host.root_pass %>

<% if @host.params['sshkey'].present? ||
@host.params['remote_execution_ssh_keys'].present? -%>
ssh_authorized_keys:
<% if @host.params['sshkey'].present? -%>
  - <%= @host.params['sshkey'] %>
<% end -%>
<% if @host.params['remote_execution_ssh_keys'].present? -%> <% @host.params['remote_execution_ssh_keys'].each do |key| -%>   - <%= key %>
<% end -%>
<% end -%>
<% end -%>
write_files:
- path: /tmp/foreman-userdata.sh
  permissions: '0755'
  content: |
    #!/bin/bash
<%= snippet 'subscription_manager_registration'-%>
<% if @host.info['parameters']['realm'] && @host.realm &&
@host.realm.realm_type == 'FreeIPA' -%>
<%= snippet 'freeipa_register'-%>
<% end -%>
  <% unless @host.operatingsystem.atomic? -%>
    # update all the base packages from the updates repository     yum -t -y -e 0 update
  <% end -%>
<%
  # safemode renderer does not support unary negation
  non_atomic = @host.operatingsystem.atomic? ? false : true   pm_set = @host.puppetmaster.empty? ? false : true
  puppet_enabled = non_atomic && (pm_set || @host.params['force-puppet'])   salt_enabled = non_atomic && (@host.params['salt_master'] ? true : false)   chef_enabled = @host.respond_to?(:chef_proxy) && @host.chef_proxy %>

<% if puppet_enabled %>
<%= snippet 'puppet_setup' %>
<% end -%>

phone_home:
url: <%= foreman_url('built') %>
post: []
tries: 10
runcmd:
- [ cloud-init-per, once, foreman-userdata, /tmp/foreman-userdata.sh ] output: {all: '| tee -a /root/install.userdata.log'}

---

any ideas?

BR

Christian
i've now created scripts for all 5 types that are assigned to an OS. the only line in is #foo

the error im getting is the same.

*Unable to save *
- Render user data template for cesar-steere.1000.local task failed with the following error: ERF22-1307 [Foreman::Renderer::SyntaxError]: Syntax error occurred while parsing the template Unnamed, make sure you have all ERB tags properly closed and the Ruby syntax is valid. The Ruby error: (string):86 :: parse error on value "<" (tLT)


··· Am Mittwoch, 6. Dezember 2017 13:40:43 UTC+1 schrieb Christian Setzer:

http://debugs.theforeman.org/foreman-debug-asEiW.tar.xz

problem i am having is that i use a user data script with 75 lines and the
error i am getting is

*Unable to save *
- Render user data template for cesar-steere.1000.local task failed with
the following error: ERF22-1307 [Foreman::Renderer::SyntaxError]: Syntax
error occurred while parsing the template Unnamed, make sure you have all
ERB tags properly closed and the Ruby syntax is valid. The Ruby error:
(string):86 :: parse error on value "<" (tLT)
while creating a new host.

i hope that 86 means the line number?!

the script is pretty much standart and the erb ruby syntax check is ok and
preview check in foreman too.

----

<%#
kind: user_data
name: Katello Kickstart default user data
oses:
- CentOS 6
- CentOS 7
- Fedora 19
- Fedora 20
- Fedora 21
- Fedora 22
- Fedora 23
-%>
#cloud-config
hostname: <%= @host.shortname %>
fqdn: <%= @host %>
manage_etc_hosts: true

groups:
- admin

users:
- default
- name: admin
primary-group: admin
groups: users
shell: /bin/bash
sudo: ['ALL=(ALL) ALL']
lock-passwd: false
passwd: <%= @host.root_pass %>

<% if @host.params['sshkey'].present? ||
@host.params['remote_execution_ssh_keys'].present? -%>
ssh_authorized_keys:
<% if @host.params['sshkey'].present? -%>
- <%= @host.params['sshkey'] %>
<% end -%>
<% if @host.params['remote_execution_ssh_keys'].present? -%>
<% @host.params['remote_execution_ssh_keys'].each do |key| -%>
- <%= key %>
<% end -%>
<% end -%>
<% end -%>
write_files:
- path: /tmp/foreman-userdata.sh
permissions: '0755'
content: |
#!/bin/bash
<%= snippet 'subscription_manager_registration'-%>
<% if @host.info['parameters']['realm'] && @host.realm &&
@host.realm.realm_type == 'FreeIPA' -%>
<%= snippet 'freeipa_register'-%>
<% end -%>
<% unless @host.operatingsystem.atomic? -%>
# update all the base packages from the updates repository
yum -t -y -e 0 update
<% end -%>
<%
# safemode renderer does not support unary negation
non_atomic = @host.operatingsystem.atomic? ? false : true
pm_set = @host.puppetmaster.empty? ? false : true
puppet_enabled = non_atomic && (pm_set || @host.params['force-puppet'])
salt_enabled = non_atomic && (@host.params['salt_master'] ? true : false)
chef_enabled = @host.respond_to?(:chef_proxy) && @host.chef_proxy
%>

<% if puppet_enabled %>
<%= snippet 'puppet_setup' %>
<% end -%>

phone_home:
url: <%= foreman_url('built') %>
post: []
tries: 10
runcmd:
- [ cloud-init-per, once, foreman-userdata, /tmp/foreman-userdata.sh ]
output: {all: '| tee -a /root/install.userdata.log'}

---

any ideas?

BR

Christian

restored a backup since nobody seems to know what to do.


··· Am Mittwoch, 6. Dezember 2017 13:40:43 UTC+1 schrieb Christian Setzer:

http://debugs.theforeman.org/foreman-debug-asEiW.tar.xz

problem i am having is that i use a user data script with 75 lines and the
error i am getting is

*Unable to save *
- Render user data template for cesar-steere.1000.local task failed with
the following error: ERF22-1307 [Foreman::Renderer::SyntaxError]: Syntax
error occurred while parsing the template Unnamed, make sure you have all
ERB tags properly closed and the Ruby syntax is valid. The Ruby error:
(string):86 :: parse error on value "<" (tLT)
while creating a new host.

i hope that 86 means the line number?!

the script is pretty much standart and the erb ruby syntax check is ok and
preview check in foreman too.

----

<%#
kind: user_data
name: Katello Kickstart default user data
oses:
- CentOS 6
- CentOS 7
- Fedora 19
- Fedora 20
- Fedora 21
- Fedora 22
- Fedora 23
-%>
#cloud-config
hostname: <%= @host.shortname %>
fqdn: <%= @host %>
manage_etc_hosts: true

groups:
- admin

users:
- default
- name: admin
primary-group: admin
groups: users
shell: /bin/bash
sudo: ['ALL=(ALL) ALL']
lock-passwd: false
passwd: <%= @host.root_pass %>

<% if @host.params['sshkey'].present? ||
@host.params['remote_execution_ssh_keys'].present? -%>
ssh_authorized_keys:
<% if @host.params['sshkey'].present? -%>
- <%= @host.params['sshkey'] %>
<% end -%>
<% if @host.params['remote_execution_ssh_keys'].present? -%>
<% @host.params['remote_execution_ssh_keys'].each do |key| -%>
- <%= key %>
<% end -%>
<% end -%>
<% end -%>
write_files:
- path: /tmp/foreman-userdata.sh
permissions: '0755'
content: |
#!/bin/bash
<%= snippet 'subscription_manager_registration'-%>
<% if @host.info['parameters']['realm'] && @host.realm &&
@host.realm.realm_type == 'FreeIPA' -%>
<%= snippet 'freeipa_register'-%>
<% end -%>
<% unless @host.operatingsystem.atomic? -%>
# update all the base packages from the updates repository
yum -t -y -e 0 update
<% end -%>
<%
# safemode renderer does not support unary negation
non_atomic = @host.operatingsystem.atomic? ? false : true
pm_set = @host.puppetmaster.empty? ? false : true
puppet_enabled = non_atomic && (pm_set || @host.params['force-puppet'])
salt_enabled = non_atomic && (@host.params['salt_master'] ? true : false)
chef_enabled = @host.respond_to?(:chef_proxy) && @host.chef_proxy
%>

<% if puppet_enabled %>
<%= snippet 'puppet_setup' %>
<% end -%>

phone_home:
url: <%= foreman_url('built') %>
post: []
tries: 10
runcmd:
- [ cloud-init-per, once, foreman-userdata, /tmp/foreman-userdata.sh ]
output: {all: '| tee -a /root/install.userdata.log'}

---

any ideas?

BR

Christian

I won't parse the code for you, but it is easy to create a ERB parser, fake some variables and methods there and perform a test. We do this with some template kinds, maybe you want to write similar test for cloud init and then run it on your template?



Check snippets, the bug can be hidden in snippets!

LZ


··· On Wed, Dec 6, 2017 at 3:36 PM, Christian Setzer <christian.setzer@gmail.com> wrote:
i've now created scripts for all 5 types that are assigned to an OS.
the only line in is #foo

the error im getting is the same.

Unable to save
Render user data template for cesar-steere.1000.local task failed with the
following error: ERF22-1307 [Foreman::Renderer::SyntaxError]: Syntax error
occurred while parsing the template Unnamed, make sure you have all ERB tags
properly closed and the Ruby syntax is valid. The Ruby error: (string):86 ::
parse error on value "<" (tLT)

Am Mittwoch, 6. Dezember 2017 13:40:43 UTC+1 schrieb Christian Setzer:

http://debugs.theforeman.org/foreman-debug-asEiW.tar.xz

problem i am having is that i use a user data script with 75 lines and the
error i am getting is

Unable to save
Render user data template for cesar-steere.1000.local task failed with the
following error: ERF22-1307 [Foreman::Renderer::SyntaxError]: Syntax error
occurred while parsing the template Unnamed, make sure you have all ERB tags
properly closed and the Ruby syntax is valid. The Ruby error: (string):86 ::
parse error on value "<" (tLT)

while creating a new host.

i hope that 86 means the line number?!

the script is pretty much standart and the erb ruby syntax check is ok and
preview check in foreman too.

----

<%#
kind: user_data
name: Katello Kickstart default user data
oses:
- CentOS 6
- CentOS 7
- Fedora 19
- Fedora 20
- Fedora 21
- Fedora 22
- Fedora 23
-%>
#cloud-config
hostname: <%= @host.shortname %>
fqdn: <%= @host %>
manage_etc_hosts: true

groups:
- admin

users:
- default
- name: admin
primary-group: admin
groups: users
shell: /bin/bash
sudo: ['ALL=(ALL) ALL']
lock-passwd: false
passwd: <%= @host.root_pass %>

<% if @host.params['sshkey'].present? ||
@host.params['remote_execution_ssh_keys'].present? -%>
ssh_authorized_keys:
<% if @host.params['sshkey'].present? -%>
- <%= @host.params['sshkey'] %>
<% end -%>
<% if @host.params['remote_execution_ssh_keys'].present? -%>
<% @host.params['remote_execution_ssh_keys'].each do |key| -%>
- <%= key %>
<% end -%>
<% end -%>
<% end -%>
write_files:
- path: /tmp/foreman-userdata.sh
permissions: '0755'
content: |
#!/bin/bash
<%= snippet 'subscription_manager_registration'-%>
<% if @host.info['parameters']['realm'] && @host.realm &&
@host.realm.realm_type == 'FreeIPA' -%>
<%= snippet 'freeipa_register'-%>
<% end -%>
<% unless @host.operatingsystem.atomic? -%>
# update all the base packages from the updates repository
yum -t -y -e 0 update
<% end -%>
<%
# safemode renderer does not support unary negation
non_atomic = @host.operatingsystem.atomic? ? false : true
pm_set = @host.puppetmaster.empty? ? false : true
puppet_enabled = non_atomic && (pm_set || @host.params['force-puppet'])
salt_enabled = non_atomic && (@host.params['salt_master'] ? true :
false)
chef_enabled = @host.respond_to?(:chef_proxy) && @host.chef_proxy
%>

<% if puppet_enabled %>
<%= snippet 'puppet_setup' %>
<% end -%>

phone_home:
url: <%= foreman_url('built') %>
post: []
tries: 10
runcmd:
- [ cloud-init-per, once, foreman-userdata, /tmp/foreman-userdata.sh ]
output: {all: '| tee -a /root/install.userdata.log'}

---

any ideas?

BR

Christian

--
You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.


--
Later,
  Lukas @lzap Zapletal
There is nothing in it anymore. The scripts are empty. No code. So there cant be 86 lines. So the snippets are out of the question.

I even made a syntax check.

[root@katello-test ~]# erb -x -T '-' test.erb | ruby -c
Syntax OK


··· -----Ursprüngliche Nachricht-----
Von: foreman-users@googlegroups.com [mailto:foreman-users@googlegroups.com] Im Auftrag von Lukas Zapletal Gesendet: Mittwoch, 6. Dezember 2017 16:54
An: Foreman users <foreman-users@googlegroups.com>
Betreff: Re: [foreman-users] Re: user-data script syntax error in line 86 when script has 75 lines

I won't parse the code for you, but it is easy to create a ERB parser, fake some variables and methods there and perform a test. We do this with some template kinds, maybe you want to write similar test for cloud init and then run it on your template?



Check snippets, the bug can be hidden in snippets!

LZ

On Wed, Dec 6, 2017 at 3:36 PM, Christian Setzer <christian.setzer@gmail.com> wrote:
i've now created scripts for all 5 types that are assigned to an OS.
the only line in is #foo

the error im getting is the same.

Unable to save
Render user data template for cesar-steere.1000.local task failed with
the following error: ERF22-1307 [Foreman::Renderer::SyntaxError]:
Syntax error occurred while parsing the template Unnamed, make sure
you have all ERB tags properly closed and the Ruby syntax is valid. The Ruby error: (string):86 ::
parse error on value "<" (tLT)

Am Mittwoch, 6. Dezember 2017 13:40:43 UTC+1 schrieb Christian Setzer:

http://debugs.theforeman.org/foreman-debug-asEiW.tar.xz

problem i am having is that i use a user data script with 75 lines
and the error i am getting is

Unable to save
Render user data template for cesar-steere.1000.local task failed
with the following error: ERF22-1307
[Foreman::Renderer::SyntaxError]: Syntax error occurred while parsing
the template Unnamed, make sure you have all ERB tags properly closed and the Ruby syntax is valid. The Ruby error: (string):86 ::
parse error on value "<" (tLT)

while creating a new host.

i hope that 86 means the line number?!

the script is pretty much standart and the erb ruby syntax check is
ok and preview check in foreman too.

----

<%#
kind: user_data
name: Katello Kickstart default user data
oses:
- CentOS 6
- CentOS 7
- Fedora 19
- Fedora 20
- Fedora 21
- Fedora 22
- Fedora 23
-%>
#cloud-config
hostname: <%= @host.shortname %>
fqdn: <%= @host %>
manage_etc_hosts: true

groups:
- admin

users:
- default
- name: admin
primary-group: admin
groups: users
shell: /bin/bash
sudo: ['ALL=(ALL) ALL']
lock-passwd: false
passwd: <%= @host.root_pass %>

<% if @host.params['sshkey'].present? ||
@host.params['remote_execution_ssh_keys'].present? -%>
ssh_authorized_keys:
<% if @host.params['sshkey'].present? -%>
- <%= @host.params['sshkey'] %>
<% end -%>
<% if @host.params['remote_execution_ssh_keys'].present? -%> <%
@host.params['remote_execution_ssh_keys'].each do |key| -%>
- <%= key %>
<% end -%>
<% end -%>
<% end -%>
write_files:
- path: /tmp/foreman-userdata.sh
permissions: '0755'
content: |
#!/bin/bash
<%= snippet 'subscription_manager_registration'-%>
<% if @host.info['parameters']['realm'] && @host.realm &&
@host.realm.realm_type == 'FreeIPA' -%> <%= snippet
'freeipa_register'-%> <% end -%>
<% unless @host.operatingsystem.atomic? -%>
# update all the base packages from the updates repository
yum -t -y -e 0 update
<% end -%>
<%
# safemode renderer does not support unary negation
non_atomic = @host.operatingsystem.atomic? ? false : true
pm_set = @host.puppetmaster.empty? ? false : true
puppet_enabled = non_atomic && (pm_set || @host.params['force-puppet'])
salt_enabled = non_atomic && (@host.params['salt_master'] ? true :
false)
chef_enabled = @host.respond_to?(:chef_proxy) && @host.chef_proxy
%>

<% if puppet_enabled %>
<%= snippet 'puppet_setup' %>
<% end -%>

phone_home:
url: <%= foreman_url('built') %>
post: []
tries: 10
runcmd:
- [ cloud-init-per, once, foreman-userdata, /tmp/foreman-userdata.sh
]
output: {all: '| tee -a /root/install.userdata.log'}

---

any ideas?

BR

Christian

--
You received this message because you are subscribed to the Google
Groups "Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.


--
Later,
  Lukas @lzap Zapletal

--
You received this message because you are subscribed to a topic in the Google Groups "Foreman users" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/foreman-users/7kN4UhaocIY/unsubscribe. To unsubscribe from this group and all its topics, send an email to foreman-users+unsubscribe@googlegroups.com. To post to this group, send email to foreman-users@googlegroups.com. Visit this group at https://groups.google.com/group/foreman-users. For more options, visit https://groups.google.com/d/optout.
same error today. yesterday everything was fine and working. i could deploy an image for the first time with userdata plugin. today

*Unable to save *
- Render user data template for alton-tibbals.1000.local task failed with the following error: ERF22-1307 [Foreman::Renderer::SyntaxError]: Syntax error occurred while parsing the template Unnamed, make sure you have all ERB tags properly closed and the Ruby syntax is valid. The Ruby error: (string):86 :: parse error on value "<" (tLT)
nothing has changed in the code...

and here are the scripts: not that it matters what in them because i could write something something in it and it would throw that error again.

since i dont want to go back on my backups and redo everything .. a solution would be prefered as you can understand.


··· --------------------
<%#
kind: user_data
name: 1_user
oses:
- CentOS 6
- CentOS 7
- Fedora 19
- Fedora 20
- Fedora 21
- Fedora 22
- Fedora 23
-%>
#cloud-config
hostname: <%= @host.shortname %>
fqdn: <%= @host %>
manage_etc_hosts: true
  
groups:
- admin
  
users:
- default
- name: admin
   primary-group: admin
   groups: users
   shell: /bin/bash
   sudo: ['ALL=(ALL) ALL']
   lock-passwd: false
   passwd: <%= @host.root_pass %>
  
identity:
  LinuxPrep:
    domain: <%= @host.domain %>
    hostName: <%= @host.shortname%>
    hwClockUTC: true
    timeZone: <%= @host.params['time-zone'] || 'UTC' %>
  
globalIPSettings:
  dnsSuffixList: [<%= @host.domain %>]
  
<% interface = @host.interfaces.first %>
nicSettingMap:
  - adapter:
      dnsDomain: <%= interface.domain %>
      dnsServerList: [<%= interface.subnet.dns_primary %>, <%= interface.subnet.dns_secondary %>]
      gateway: [<%= interface.subnet.gateway %>]
      ip: <%= interface.ip %>
      subnetMask: <%= interface.subnet.mask %>

write_files:
- path: /tmp/foreman-userdata.sh
   permissions: '0755'
   content: |
       #!/bin/bash
       yum -t -y -e 0 update
<%= indent(7) { snippet('1_subscription_manager_registration') } %> <%= indent(7) { snippet('1_puppet_setup') } %>

runcmd:
- [ cloud-init-per, once, foreman-userdata, /tmp/foreman-userdata.sh ]

phone_home:
  url: <%= foreman_url('built') %>
  post: []
  tries: 10

-------------------------------------

/usr/bin/yum -t -y -e 0 install subscription-manager
/usr/bin/rpm -ivh <%= subscription_manager_configuration_url(@host) %> /usr/bin/echo "Registering the System"
/usr/sbin/subscription-manager register --org="<%=
@host.rhsm_organization_label %>" --name="<%= @host.name %>" --activationkey="<%= @host.params['kt_activation_keys'] %>" /usr/bin/yum -t -y -e 0 install katello-agent
/usr/sbin/chkconfig goferd on

-------------------------------------

<%#
kind: snippet
name: 1_puppet_setup
description: this snippet will configure the Puppet agent
%>
<%
os_family = @host.operatingsystem.family
os_major = @host.operatingsystem.major.to_i
os_name = @host.operatingsystem.name

linux_package = 'puppet-agent'
etc_path = '/etc/puppetlabs/puppet'
bin_path = '/opt/puppetlabs/puppet/bin'
%>

/usr/bin/yum -t -y install <%= linux_package %>

cat > <%= etc_path %>/puppet.conf << EOF
<%= snippet 'puppet.conf' %>
EOF

puppet_unit=puppet
/usr/bin/systemctl enable ${puppet_unit}
/sbin/chkconfig --level 345 puppet on
<%= bin_path %>/puppet resource service puppet enable=true
<%= bin_path %>/puppet resource service puppet ensure=running

----------------------------

<%#
kind: snippet
name: 1_puppet.conf
%>
<%
  os_family = @host.operatingsystem.family
  os_name = @host.operatingsystem.name

  var_dir = '/opt/puppetlabs/puppet/cache'
  log_dir = '/var/log/puppetlabs/puppet'
  run_dir = '/var/run/puppetlabs'
  ssl_dir = '/etc/puppetlabs/puppet/ssl'
%>
[main]
<%- unless @host.params['dns_alt_names'].to_s.empty? -%>
dns_alt_names = <%= @host.params['dns_alt_names'] %>
<%- end -%>
vardir = <%= var_dir %>
logdir = <%= log_dir %>
rundir = <%= run_dir %>
ssldir = <%= ssl_dir %>

[agent]
pluginsync = true
report = true
ignoreschedules = true
ca_server = <%= @host.puppet_ca_server %>
certname = <%= @host.certname %>
environment = <%= @host.environment %>
server = <%= @host.puppetmaster %>