Subject: [chef] I want to execute the script without using execute resource or script resource


script 'user' do
interpreter 'bash'
user 'root'
code <<-EOH
adduser -g test1 test2
EOH
end

replace this with

    group  'test1' do
      action :create
    end

    user 'test2' do
      manage_home true
      password encrypted_password_string
      group 'test1'
      shell '/bin/bash'
      comment 'test user 2'
      action :create
    end

script 'executing_installation' do
interpreter 'bash'
user 'root'
code <<-EOH
sh /test/some/script/recipe.sh >> /tmp/test.txt
EOH
cwd /tmp/tmp2
end

You can use a bash block here but its effectively the same you would still need a guard

    bash 'executing_installation' do
      cwd /tmp/tmp2
      code <<-EOH
      sh /test/some/script/recipe.sh >> /tmp/test.txt
      EOH
    end

script 'port_redirection' do
interpreter 'bash'
user 'root'
code <<-EOH
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
chmod +x /etc/test/test1
EOH
end

Same for this block of code

    bash 'executing_installation' do
      code <<-EOH
      iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
      EOH
    end

This you would need to just specify the node and it will change the file permissions

    file '/etc/test/test1' do
    mode '0755'
    end
Why are you not allowed to use guards?

---