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: <class > 'yaml.parser.ParserError'>\nexception: while parsing a block collection\n > in \"<unicode string>\", line 3, column 3:\n - name: Update Red Hat > machine\n ^\nexpected <block end>, but found '?'\n in \"<unicode > 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.