Re: [ansible-project] Re: Need help about Ansible block syntax

2018-02-19 Thread Brian Coca
'tasks' is a property of a play, it should ONLY appear at the play level





-- 
--
Brian Coca

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7dXBV2XZ%2BMdmHwPOJpAbiA6yiYH_9%3DHu6JTujSVynX%3Dew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Need help about Ansible block syntax

2018-02-01 Thread JiElPe-Fr38
Thanks all for your help.
I have been really bored with the block... but I finally succeed. The 
ansible / yaml syntax is not always straightforward to understand (or I 
lack some skills).

I went back to the ansible block documentation 
, and make a 
trial replacing my main.yml file with the example on the page, i.e.  :
cat roles/devTools/tasks/main.yml
tasks:
  - name: Install Apache
block:
  - yum: name={{ item }} state=installed
with_items:
  - httpd
  - memcached
  - template: src=templates/src.j2 dest=/etc/foo.conf
  - service: name=bar state=started enabled=True
when: ansible_distribution == 'CentOS'
become: true
become_user: root

And I still get an error saying that the role must contain a list of task :
ERROR! The tasks/main.yml file for role 'devTools' must contain a list of 
tasks

The error appears to have been in 
'/home/jeanlupi/centos_test/myKnowledge/devOps/playbook/roles/devTools/tasks/main.yml'
: line 1, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


tasks:
^ here

Ok... I removed "tasks" (don't clearly understand why it must not be 
there...) and the problem disappeared.
After several other syntax errors (probably not totally sticked to block), 
I succeeded with :

cat roles/devTools/tasks/RedHat.yml
  - name: Update Red Hat machine
block:
  - yum: update_cache=yes name="*" state=latest
notify: "restart {{ ansible_os_family }} host"
  - yum: name="{{item}}" state=present
with_items: "{{ toolList }}"
notify: "restart {{ ansible_os_family }} host"
when: ansible_pkg_mgr == 'yum'
become: true
become_user: root



As mentioned in the answers, notify must not be set at block level, but 
after each enclosed task.

Thanks for your help.
Have a nice day.
JiElPe

Le mercredi 31 janvier 2018 16:29:00 UTC+1, JiElPe-Fr38 a écrit :
>
> Dear all,
>
> I am quite new to Ansible and try to "make a tour"...
> I am using ansible 2.4.2.0 with cygwin64 on Win7.
>
>
> I am currently make a personal training and find that I could use a block 
> to "enclose" (ok, perhaps wrong term) a couple of task that have some 
> common "properties" (like become_user: root ...).
> The idea is to change this :
>
> ---
> - name: Update Red Hat machine
>   yum:
> update_cache: yes
> name: '*'
> state: latest
>   when: ansible_pkg_mgr == 'yum'
>   become: true
>   become_user: root
>   ignore_errors: yes
>   notify: "restart {{ ansible_os_family }} host"
>
> - name: Install RedHat tools
>   yum:
> name: "{{ item }}"
> state: present
>   with_items: "{{ toolList }}"
>   when: ansible_pkg_mgr == 'yum'
>   become: true
>   become_user: root
>   ignore_errors: yes
>   notify: "restart {{ ansible_os_family }} host"
>
>
>
> into a block based syntax so that I can factorize the become / notify and 
> when statement.
> II have made several trials without any success.
> Playing the file below :
> ---
> -block:
>   - name: Update Red Hat machine
> yum:
>   update_cache: yes
>   name: '*'
>   state: latest
>
>   - name: Install RedHat tools
> yum:
>   name: "{{ item }}"
>   state: present
>   with_items: "{{ toolList }}"
>
>   when: ansible_pkg_mgr == 'yum'
>   become: true
>   become_user: root
>   ignore_errors: yes
>   notify: "restart {{ ansible_os_family }} host"
>
> I get this error :
> fatal: [ci-server]: FAILED! => {"reason": "Syntax Error while loading 
> YAML.\n\n\nThe error appears to have been in 
> '/home/jeanlupi/centos_test/myKnowledge/devOps/playbook/roles/devTools/tasks/RedHat.yml':
>  
> line 16, column 3, but may\nbe elsewhere in the file depending on the exact 
> syntax problem.\n\nThe offending line appears to be:\n\n\n  when: 
> ansible_pkg_mgr == 'yum'\n  ^ here\n\nexception type:  'yaml.parser.ParserError'>\nexception: while parsing a block collection\n  
> in \"\", line 3, column 3:\n  - name: Update Red Hat 
> machine\n  ^\nexpected , but found '?'\n  in \" string>\", line 16, column 3:\n  when: ansible_pkg_mgr == 'yum'\n  
> ^"}
>
>
>
> If someone could help I would be very glad ! 
>
> Thanks !
> JiElPe
>
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/01e8cbe9-15eb-4c6a-bc6c-ef9831b745d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Need help about Ansible block syntax

2018-01-31 Thread Malcolm Hussain-Gambles
Notify should go after each of the tasks.
You could set a fact in the block then check that and notify afterwards though

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/61ec61f9-173e-4f69-b6f6-54ea8e0a454e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Need help about Ansible block syntax

2018-01-31 Thread ZillaYT
block does not support ALL the features of a simple task so this may be 
your issue. For example, it may not support notify, but you'll need to look 
at this.

On Wednesday, January 31, 2018 at 10:29:00 AM UTC-5, JiElPe-Fr38 wrote:
>
> Dear all,
>
> I am quite new to Ansible and try to "make a tour"...
> I am using ansible 2.4.2.0 with cygwin64 on Win7.
>
>
> I am currently make a personal training and find that I could use a block 
> to "enclose" (ok, perhaps wrong term) a couple of task that have some 
> common "properties" (like become_user: root ...).
> The idea is to change this :
>
> ---
> - name: Update Red Hat machine
>   yum:
> update_cache: yes
> name: '*'
> state: latest
>   when: ansible_pkg_mgr == 'yum'
>   become: true
>   become_user: root
>   ignore_errors: yes
>   notify: "restart {{ ansible_os_family }} host"
>
> - name: Install RedHat tools
>   yum:
> name: "{{ item }}"
> state: present
>   with_items: "{{ toolList }}"
>   when: ansible_pkg_mgr == 'yum'
>   become: true
>   become_user: root
>   ignore_errors: yes
>   notify: "restart {{ ansible_os_family }} host"
>
>
>
> into a block based syntax so that I can factorize the become / notify and 
> when statement.
> II have made several trials without any success.
> Playing the file below :
> ---
> -block:
>   - name: Update Red Hat machine
> yum:
>   update_cache: yes
>   name: '*'
>   state: latest
>
>   - name: Install RedHat tools
> yum:
>   name: "{{ item }}"
>   state: present
>   with_items: "{{ toolList }}"
>
>   when: ansible_pkg_mgr == 'yum'
>   become: true
>   become_user: root
>   ignore_errors: yes
>   notify: "restart {{ ansible_os_family }} host"
>
> I get this error :
> fatal: [ci-server]: FAILED! => {"reason": "Syntax Error while loading 
> YAML.\n\n\nThe error appears to have been in 
> '/home/jeanlupi/centos_test/myKnowledge/devOps/playbook/roles/devTools/tasks/RedHat.yml':
>  
> line 16, column 3, but may\nbe elsewhere in the file depending on the exact 
> syntax problem.\n\nThe offending line appears to be:\n\n\n  when: 
> ansible_pkg_mgr == 'yum'\n  ^ here\n\nexception type:  'yaml.parser.ParserError'>\nexception: while parsing a block collection\n  
> in \"\", line 3, column 3:\n  - name: Update Red Hat 
> machine\n  ^\nexpected , but found '?'\n  in \" string>\", line 16, column 3:\n  when: ansible_pkg_mgr == 'yum'\n  
> ^"}
>
>
>
> If someone could help I would be very glad ! 
>
> Thanks !
> JiElPe
>
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2a2c9c4b-00cc-4eb6-809d-e6d37e68e88c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.