Hello,
I did not know the set_fact plugin it is worth investigating thanks.
Here are 2 other options :
(1) concatenate via echo
- hosts: localhost
gather_facts: no
tasks:
- name: initialize nginx build options
command: echo "./configure"
register: nginx_build_options
- name: nginx_spdy option
command: echo "{{ nginx_build_options.stdout ~ '
--with-http_spdy_module'}}"
register: nginx_build_options
when: nginx_spdy
- name: nginx_upload_progress option
command: echo "{{ nginx_build_options.stdout ~ '
--add-module=/var/opt/nginx-upload-progress-module/'}}"
register: nginx_build_options
when: nginx_upload_progress
- name: output
debug: var=nginx_build_options
beware: this will make a lot of ssh round trips i guess i you have tons of
options. maybe using local_action: could help here.
(2) template: and command:
use the template: module to send to the remote a templated build script.
in this template, you will be able to hide all the complexity of the
configure options without making a long list of nearly useless tasks + you
will send a lot less ssh commands
then execute your script with the command: module
Hope this helps
Jerome
Le vendredi 15 novembre 2013 08:35:13 UTC+1, Peter Droogmans a écrit :
>
> I started using ansible a week a go and I'm loving it, but I ran into a
> problem with conditions. I read that concatenation isn't supported so I
> tried the following
>
> This works if all options are set to true, but with the example below it
> fails because one of the options is false and the variable is defined but
> contains no stdout. I tried adding the following snippet, but apparently
> the variable is always set even if the condition is not met.
>
> - name: Nginx | Set null option
> command: echo
> register: nginx_cache_purge_option
> when: not nginx_cache_purge
>
>
> I guess there's probably a better way to handle this. Keep in mind that
> there will be more options
>
> settings.yml:
> _NGINX_VERSION: '1.5.6'
> nginx_spdy: true
> nginx_upload_progress: true
> nginx_cache_purge: false
>
> roles/nginx/tasks/build_from_source.yml:
> - name: Nginx | Update apt cache
> apt: update_cache=yes cache_valid_time=3600
>
> - name: Nginx | Dependencies
> apt: pkg={{ item }} state=present
> with_items:
> - libpcre3
> - libpcre3-dev
> - libgeoip-dev
>
> - name: Nginx | Remove nginx dir
> command: chdir=/var/opt removes=/var/opt/nginx* rm -rf /var/opt/nginx*
>
> # nginx
> - name: Nginx | Get archive
> get_url:
> url=http://files.aegir.cc/dev/src/nginx-{{<http://www.google.com/url?q=http%3A%2F%2Ffiles.aegir.cc%2Fdev%2Fsrc%2Fnginx-%257B%257B&sa=D&sntz=1&usg=AFQjCNEgyFLQe_DLZ5tgO1Xh7pH_aOWubA>_NGINX_VERSION
> }}.tar.gz dest=/var/opt/nginx-{{ _NGINX_VERSION }}.tar.gz
>
> - name: Nginx | Extract archive
> command: chdir=/var/opt creates=/var/opt/nginx-{{ _NGINX_VERSION }} tar
> xvf nginx-{{ _NGINX_VERSION }}.tar.gz
>
> - name: Nginx | Remove archive
> command: removes=/var/opt/nginx-{{ _NGINX_VERSION }}.tar.gz rm
> /var/opt/nginx-{{ _NGINX_VERSION }}.tar.gz
>
> # nginx-upload-progress-module
> - name: Nginx | Get archive
> get_url: url=
> http://files.aegir.cc/dev/src/nginx-upload-progress-module.tar.gz<http://www.google.com/url?q=http%3A%2F%2Ffiles.aegir.cc%2Fdev%2Fsrc%2Fnginx-upload-progress-module.tar.gz&sa=D&sntz=1&usg=AFQjCNGHZUhD0WtLxGNkWKQqS2PkjI-vFA>dest=/var/opt/nginx-upload-progress-module.tar.gz
> when: nginx_upload_progress
>
> - name: Nginx | Extract archive
> command: chdir=/var/opt creates=/var/opt/nginx-upload-progress-module
> tar xvf nginx-upload-progress-module.tar.gz
> when: nginx_upload_progress
>
> - name: Nginx | Remove archive
> command: removes=/var/opt/nginx-upload-progress-module.tar.gz rm
> /var/opt/nginx-upload-progress-module.tar.gz
> when: nginx_upload_progress
>
> - name: Nginx | Set option
> command: echo --add-module=/var/opt/nginx-upload-progress-module/
> register: nginx_upload_progress_option
> when: nginx_upload_progress
>
> # ngx-cache-purge
> - name: Nginx | Get archive
> get_url:
> url=http://files.aegir.cc/dev/src/ngx-cache-purge.tar.gz<http://www.google.com/url?q=http%3A%2F%2Ffiles.aegir.cc%2Fdev%2Fsrc%2Fngx-cache-purge.tar.gz&sa=D&sntz=1&usg=AFQjCNH4Fxjf5YiN-aAO-XXvI88QoyGb-g>dest=/var/opt/ngx-cache-purge.tar.gz
> when: nginx_cache_purge
>
> - name: Nginx | Extract archive
> command: chdir=/var/opt creates=/var/opt/ngx-cache-purge tar xvf
> ngx-cache-purge.tar.gz
> when: nginx_cache_purge
>
> - name: Nginx | Remove archive
> command: removes=/var/opt/ngx-cache-purge.tar.gz rm
> /var/opt/ngx-cache-purge.tar.gz
> when: nginx_cache_purge
>
> - name: Nginx | Set option
> command: echo --add-module=/var/opt/ngx-cache-purge/
> register: nginx_cache_purge_option
> when: nginx_cache_purge
>
> # spdy - nginx_spdy
> - name: Nginx | Set option
> command: echo --with-http_spdy_module
> register: nginx_spdy_option
> when: nginx_spdy
>
> # compile time
> - name: Nginx | Configure
> command: chdir=/var/opt/nginx-{{ _NGINX_VERSION }} sh ./configure
> --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf
> --error-log-path=/var/log/nginx/error.log
> --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid
> --lock-path=/var/lock/nginx.lock --user=www-data --group=www-data
> --with-http_realip_module --with-http_gzip_static_module
> --with-http_stub_status_module --with-http_ssl_module
> --with-http_dav_module --with-http_flv_module --with-http_mp4_module
> --without-mail_pop3_module --without-mail_imap_module
> --without-mail_smtp_module --without-http_scgi_module
> --without-http_uwsgi_module --with-ipv6 --with-http_geoip_module
> --with-debug {{ nginx_spdy_option.stdout }} {{
> nginx_cache_purge_option.stdout }} {{ nginx_upload_progress_option.stdout }}
> - name: Nginx | Make
> command: chdir=/var/opt/nginx-{{ _NGINX_VERSION }} make --quiet
> - name: Nginx | Install
> command: chdir=/var/opt/nginx-{{ _NGINX_VERSION }} make --quiet install
>
>
>
--
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].
For more options, visit https://groups.google.com/groups/opt_out.