ansible include_role syntax problem

44 views
Skip to first unread message

Meir Yanovich

unread,
May 6, 2020, 6:20:30 AM5/6/20
to Ansible Project
I try to include_rule but i keep getting errors on the wrong syntax 
this is my file structure :


   
├── roles  
   
  └── utilities
   
      ├── defaults
   
      ├── files
   
      ├── handlers
   
      ├── meta
   
      ├── tasks
   
        └── d_pack.yml
   
      ├── templates
   
      └── vars
   
└── test4.yml
   

the rule d_pack.yml

    ---
   
- name: d packa
      get_url
:
        url_username
:
        url_password
:
        dest
:
        url
:
        owner
:
       
group:


the test4.yml

    ---
   
- name: check if exsist
      hosts
: localhost
      gather_facts
: false
      tasks
:
         
- name: this is test
           include_role
:
             
static: no
             name
: utilities
             tasks_from
: d_pack
           vars
:
             url_username
: "{{ user }}"
             url_password
: "{{ pass }}"
             dest
: "{{ ansible_env.APP }}/"
             url
: "{{ package_url }}"
             owner
: "{{ ansible_user }}"
             
group: "{{ ansible_user }}"

getting this error:

The error appears to be in '/home/ec2-user/ansible/test4.yml': line 6, column 8, but may
be elsewhere
in the file depending on the exact syntax problem.


The offending line appears to be:


  tasks
:
     
- name: this is test
       
^ here



Stefan Hornburg (Racke)

unread,
May 6, 2020, 6:49:58 AM5/6/20
to ansible...@googlegroups.com
On 5/6/20 12:20 PM, Meir Yanovich wrote:
> I try to include_rule but i keep getting errors on the wrong syntax 
> this is my file structure :
> |
>
>
>     ├──roles  
>     │  └──utilities
>     │      ├──defaults
>     │      ├──files
>     │      ├──handlers
>     │      ├──meta
>     │      ├──tasks
>     │      │  └──d_pack.yml
>     │      ├──templates
>     │      └──vars
>     └──test4.yml
>    
> |
>
> the rule d_pack.yml
>
> |
>     ---
>     -name:d packa
>       get_url:
>         url_username:
>         url_password:
>         dest:
>         url:
>         owner:
>         group:
> |
>


The values are missing here.

Regards
Racke

>
> the test4.yml
>
> |
>     ---
>     -name:check ifexsist
>       hosts:localhost
>       gather_facts:false
>       tasks:
>          -name:thisistest
>            include_role:
>              static:no
>              name:utilities
>              tasks_from:d_pack
>            vars:
>              url_username:"{{ user }}"
>              url_password:"{{ pass }}"
>              dest:"{{ ansible_env.APP }}/"
>              url:"{{ package_url }}"
>              owner:"{{ ansible_user }}"
>              group:"{{ ansible_user }}"
> |
>
> getting this error:
>
> |
> Theerror appears to be in'/home/ec2-user/ansible/test4.yml':line 6,column 8,but may
> be elsewhere inthe file depending on the exact syntax problem.
>
>
> Theoffending line appears to be:
>
>
>   tasks:
>      -name:thisistest
>        ^here
>
> |
>
>
> --
> 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-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/760f037b-103a-4885-b101-fb13c5909910%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/760f037b-103a-4885-b101-fb13c5909910%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Meir Yanovich

unread,
May 6, 2020, 6:57:50 AM5/6/20
to Ansible Project
Thanks for your fast replay , but now 
when i set default values in the rules 
i do not want them to evaluate only from my include_rule I'm getting error:
- name:d packa
  get_url
:

    url_username
: temp
    url_password
: tmp
    dest
: tmp
    url
: tmp
    owner
: tmp
   
group: tmp


running in debug mode i can see that the rule got invoked with the dummy args 
this is not what i want .. i want it only to be invoked with the values i set in vars :
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/ec2-user/.ansible/tmp/ansible-tmp-1588762539.1880841-18280-15848856136034/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/********/ansible_get_url_payload_xex4nmel/ansible_get_url_payload.zip/ansible/module_utils/urls.py", line 1494, in fetch_url
    unix_socket=unix_socket, ca_path=ca_path)
  File "/********/ansible_get_url_payload_xex4nmel/ansible_get_url_payload.zip/ansible/module_utils/urls.py", line 1390, in open_url
    unredirected_headers=unredirected_headers)
  File "/********/ansible_get_url_payload_xex4nmel/ansible_get_url_payload.zip/ansible/module_utils/urls.py", line 1264, in open
    request = RequestWithMethod(url, method, data)
  File "/********/ansible_get_url_payload_xex4nmel/ansible_get_url_payload.zip/ansible/module_utils/urls.py", line 643, in __init__
    urllib_request.Request.__init__(self, url, data, headers, origin_req_host, unverifiable)
  File "/usr/lib64/python3.7/urllib/request.py", line 328, in __init__
    self.full_url = url
  File "/usr/lib64/python3.7/urllib/request.py", line 354, in full_url
    self._parse()
  File "/usr/lib64/python3.7/urllib/request.py", line 383, in _parse
    raise ValueError("unknown url type: %r" % self.full_url)
fatal: [localhost]: FAILED! => changed=false
  invocation:
    module_args:
      attributes: null
      backup: null
      checksum: ''
      client_cert: null
      client_key: null
      content: null
      delimiter: null
      dest: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
      directory_mode: null
      follow: false
      force: false
      force_basic_auth: false
      group: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
      headers: null
      http_agent: ansible-httpget
      mode: null
      owner: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
      regexp: null
      remote_src: null
      selevel: null
      serole: null
      setype: null
      seuser: null
      sha256sum: ''
      src: null
      timeout: 10
      tmp_dest: null
      unsafe_writes: null
      url: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
      url_password: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
      url_username: temp
      use_proxy: true
      validate_certs: true
  msg: 'unknown url type: ''********'''
  status: -1
  url: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
[localhost] TASK: utilities : Download package (debug)> p task.args
{'_ansible_check_mode': False,
 '_ansible_debug': False,
 '_ansible_diff': False,
 '_ansible_keep_remote_files': False,
 '_ansible_module_name': 'get_url',
 '_ansible_no_log': False,
 '_ansible_module_name': 'get_url',
 '_ansible_no_log': False,
 '_ansible_remote_tmp': '~/.ansible/tmp',
 '_ansible_selinux_special_fs': ['fuse',
                                 'nfs',
                                 'vboxsf',
                                 'ramfs',
                                 '9p',
                                 'vfat'],
 '_ansible_shell_executable': '/bin/sh',
 '_ansible_socket': None,
 '_ansible_string_conversion_action': 'warn',
 '_ansible_syslog_facility': 'LOG_USER',
 '_ansible_tmpdir': '/home/ec2-user/.ansible/tmp/ansible-tmp-1588762539.1880841-18280-15848856136034/',
 '_ansible_verbosity': 3,
 '_ansible_version': '2.9.7',
 'dest': 'tmp',
 'group': 'tmp',
 'owner': 'tmp',
 'url': 'tmp',
 'url_password': 'tmp',
 'url_username': 'temp'}

Stefan Hornburg (Racke)

unread,
May 6, 2020, 7:02:57 AM5/6/20
to ansible...@googlegroups.com
On 5/6/20 12:57 PM, Meir Yanovich wrote:
> Thanks for your fast replay , but now 
> when i set default values in the rules 
> i do not want them to evaluate only from my include_rule I'm getting error:
> |
> -name:d packa
>   get_url:
>     url_username:temp
>     url_password:tmp
>     dest:tmp
>     url:tmp
>     owner:tmp
>     group:tmp
>
>

Well, you need to specify which variable is used for each of these values, e.g.

url: "{{ url }}"

Regards
Racke
>     -name:d packa
> Theerror appears to be in'/home/ec2-user/ansible/test4.yml':line 6,column 8,but may
> be elsewhere inthe file depending on the exact syntax problem.
>
>
> Theoffending line appears to be:
>
>
>   tasks:
>      -name:thisistest
>        ^here
>
> |
>
>
> --
> 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-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

Meir Yanovich

unread,
May 6, 2020, 7:06:34 AM5/6/20
to Ansible Project
i see , 
in my vars: i will refer to those variable names ? not the module properties?

Stefan Hornburg (Racke)

unread,
May 6, 2020, 7:12:06 AM5/6/20
to ansible...@googlegroups.com
On 5/6/20 1:06 PM, Meir Yanovich wrote:
> i see , 
> in my vars: i will refer to those variable names ? not the module properties?
>

Your variable names in the vars block match the module properties, so the task in the role should look like:

-name:d packa
get_url:
url_username: "{{ url_username }}"
url_password: "{{ url_password }}"
....

Regards
Racke
> > ansible...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/b9f70f4e-a6d0-4683-b8e8-cbfb41e56b5c%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/b9f70f4e-a6d0-4683-b8e8-cbfb41e56b5c%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

Meir Yanovich

unread,
May 6, 2020, 7:16:46 AM5/6/20
to Ansible Project
Thanks its working, final question 
can i hold default values in the role ?
so if no value is suplied in the include_role in the vars section it will use the default?

so that i could invoke :
- name: this is test
           include_role
:

             name
: utilities
             tasks_from
: d_pack


           

and  also :
- name: this is test
           include_role
:
>     > ansible...@googlegroups.com <javascript:> <mailto:ansible-project+unsub...@googlegroups.com <javascript:>>.
>     > To view this discussion on the web visit
>     > https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com>
>     >
>     <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
>
>
>     --
>     Ecommerce and Linux consulting + Perl and web application programming.
>     Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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

Vladimir Botka

unread,
May 6, 2020, 7:22:05 AM5/6/20
to Meir Yanovich, ansible...@googlegroups.com
On Wed, 6 May 2020 03:20:30 -0700 (PDT)
Meir Yanovich <meir...@gmail.com> wrote:

> ---
> - name: check if exsist
> hosts: localhost
> gather_facts: false
> tasks:
> - name: this is test
> include_role:
> static: no
> name: utilities
> tasks_from: d_pack
> vars:
> url_username: "{{ user }}"
> url_password: "{{ pass }}"
> dest: "{{ ansible_env.APP }}/"
> url: "{{ package_url }}"
> owner: "{{ ansible_user }}"
> group: "{{ ansible_user }}"
>

> The error appears to be in '/home/ec2-user/ansible/test4.yml': line 6,
> column 8, but may be elsewhere in the file depending on the exact syntax
> problem.
> The offending line appears to be:
> tasks:
> - name: this is test
> ^ here

Remove "static: no". There is no such parameter in module "include_role". Fix
the indentation.

---
- name: check if exsist
hosts: localhost
gather_facts: false
tasks:
- name: this is test
include_role:
name: utilities
tasks_from: d_pack
vars:
url_username: "{{ user }}"
url_password: "{{ pass }}"
dest: "{{ ansible_env.APP }}/"
url: "{{ package_url }}"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"

HTH,

-vlado

Stefan Hornburg (Racke)

unread,
May 6, 2020, 7:25:12 AM5/6/20
to ansible...@googlegroups.com
On 5/6/20 1:16 PM, Meir Yanovich wrote:
> Thanks its working, final question 
> can i hold default values in the role ?
> so if no value is suplied in the include_role in the vars section it will use the default?
>

Sure, you could put the defaults into defaults/main.yml in your role or use the
default filter in the task:

-name:d packa
get_url:
url_username: "{{ url_username | default('nobody'}}"
url_password: "{{ url_password | default('nevairbe'}}"

Regards
Racke
> >     > ansible...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>
> <javascript:>>.
> >     > To view this discussion on the web visit
> >     > https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com>
> >     <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com>>
> >     >
> >    
> <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com?utm_medium=email&utm_source=footer>
>
> >    
> <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/d8de10b9-e94f-4c66-aca8-9b7281d90885%40googlegroups.com?utm_medium=email&utm_source=footer>>>.
>
> >
> >
> >
> >
> >
> >     --
> >     Ecommerce and Linux consulting + Perl and web application programming.
> >     Debian and Sympa administration. Provisioning with Ansible.
> >
> > --
> > 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...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/ansible-project/b9f70f4e-a6d0-4683-b8e8-cbfb41e56b5c%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/b9f70f4e-a6d0-4683-b8e8-cbfb41e56b5c%40googlegroups.com>
> >
> <https://groups.google.com/d/msgid/ansible-project/b9f70f4e-a6d0-4683-b8e8-cbfb41e56b5c%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/b9f70f4e-a6d0-4683-b8e8-cbfb41e56b5c%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/1191a1a6-8e40-4dc5-a331-1e4231e628a7%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/1191a1a6-8e40-4dc5-a331-1e4231e628a7%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

Meir Yanovich

unread,
May 6, 2020, 7:38:58 AM5/6/20
to Ansible Project
Thanks allot for your quick answers and help 




On Wednesday, May 6, 2020 at 1:20:30 PM UTC+3, Meir Yanovich wrote:

Meir Yanovich

unread,
May 6, 2020, 7:42:34 AM5/6/20
to Ansible Project
now i facing a new problem as the playbook is in inner directory and the role is in the main dir 
and it seams ansible don't see it 
is there way to access the main roles dir ? ( the one under ansible dir )
Reply all
Reply to author
Forward
0 new messages