Hey Sebastian,
thanks for your reply.
But once I read from the csv how do I get the variables populated and how
to iterate?
I have something like this now
- hosts: dev
become: yes
become_method: sudo
vars:
username: "{{ users.0 }}"
ad_username: "{{ users.1 }}"
vhost_id: "{{ users.2 }}"
tasks:
- name: Read users from CSV file and return a list
read_csv:
path: /home/ncontu/users.csv
delimiter: ';'
register: users
- name: Ansible Template
template:
src:
/usr/local/cmd-sysadmin/automation/ansible/cmd/files/templates/apache_vhost_api_private_public.j2
dest: /usr/local/apache2.4/conf/vhosts/v2/{{ vhost_id }}_{{
username }}_apis.vhost.conf
loop: users
- name: Add vhost to httpd.conf
shell: echo "Include conf/vhosts/v2/{{ vhost_id }}_{{ username
}}_apis.vhost.conf" >> /usr/local/apache2.4/conf/httpd.conf
loop: users
Il giorno giovedì 13 giugno 2019 15:50:59 UTC+2, Sebastian Meyer ha scritto:
>
> Hi Nicola,
>
> On 13.06.19 15:06, Nicola Contu wrote:
> > As I have too many vhosts to be created, I got a file from where I would
> > like to read content, iterate it, populate variables and push the file.
> >
> > The file is like this :
> > 5;yyy;yyyyy
> > 70;zzzz;zzz
> >
> > I can modify the file to include the header, to be , delimited..
> whatever.
>
> Since this is basically a CSV file, you might have a look at the
> read_csv module.
>
> https://docs.ansible.com/ansible/latest/modules/read_csv_module.html
>
> This is only available in Ansible 2.8 though, for older versions you
> might use the csvfile lookup.
>
> https://docs.ansible.com/ansible/latest/plugins/lookup/csvfile.html
>
> Regards
> Sebastian
>
> --
> Sebastian Meyer
> Linux Consultant & Trainer
> Mail: [email protected] <javascript:>
>
> B1 Systems GmbH
> Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
> GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/a6d3036d-7f8e-41ff-9e76-15141aa53d02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.