Reputation: 453
I am trying to convert following chef recipe into Ansible. What could be the equivalent of it ?.. I am familiar with Ansible. Is it correct that there are going to be three directories created ?. Such as /usr/share/agentone/lib ; /usr/share/agentone/etc ; /usr/share/agentone/bin and all of them have the 0755 mode on ?
if node[:platform_family] == 'debian'
%w{lib etc bin}.each do |dir|
directory "/usr/share/agentone/#{dir}" do
mode '0755'
owner 'root'
group 'root'
action :create
recursive true
end
end
directory '/var/log/agentone'
directory 'var/run/agentone'
link '/usr/share/agentone/logs' do
to '/var/log/agentone'
end
template '/etc/init.d/agentone' do
owner 'root'
group 'root'
mode '750'
source 'agentone.init.erb'
variables(
:version => node[:base][:agent][:agent_artifact][:version]
)
end
end
What could be the best way to write in Ansible ?
Upvotes: 1
Views: 2986
Reputation: 20759
The ansible version of this would be something like this:
- name: create dirs
file: path=/usr/share/agentone/{{ item }}
state=directory
owner=root
group=root
mode=0755
recurse=true
with_items:
- lib
- etc
- bin
when: ansible_distribution == 'Debian'
Edit: With respect to the additional code you added:
- name: symlink /usr/share/agentone/logs
file: path=/usr/share/agentone/logs
src=/var/log/agentone
state=link
- name: template /etc/init.d/agentone
template: src=agentone.init.erb
dest=/etc/init.d/agentone
owner=root
group=root
mode=0750
With respect to the variables used in the template task, they just need to be added to your inventory file, a vars file, or anywhere else Ansible variables can be defined.
Upvotes: 3