how to use included variable from file with jinja2 template and with_items2019 Community Moderator Electionfor loop in jinja2Bash script and yml file outputHow to modify sudoers file with ansible?How do I open a file with ansible-vault edit from inside vim?Taking register value and using it later as variableHow to make playbook idempotent with raw module?separator value from fact variable in ansibleHow to save ansible stdout.lines to a file is in list formatreplace specific line in file with ansibleHow do i store a variable value to a file in new lines on ansibleAnsible Playbook: Get value from variable

What are the consequences of changing the number of hours in a day?

What is the tangent at a sharp point on a curve?

When should a starting writer get his own webpage?

Gauss brackets with double vertical lines

Nested Dynamic SOQL Query

Should I be concerned about student access to a test bank?

Exit shell with shortcut (not typing exit) that closes session properly

Is VPN a layer 3 concept?

Would this string work as string?

Do native speakers use "ultima" and "proxima" frequently in spoken English?

Do people actually use the word "kaputt" in conversation?

What is the reasoning behind standardization (dividing by standard deviation)?

Why is "la Gestapo" feminine?

Air travel with refrigerated insulin

Does the Shadow Magic sorcerer's Eyes of the Dark feature work on all Darkness spells or just his/her own?

Why is this tree refusing to shed its dead leaves?

Hot air balloons as primitive bombers

Unfrosted light bulb

Should a narrator ever describe things based on a characters view instead of fact?

If I cast the Enlarge/Reduce spell on an arrow, what weapon could it count as?

Did Nintendo change its mind about 68000 SNES?

Can other pieces capture a threatening piece and prevent a checkmate?

Help with identifying unique aircraft over NE Pennsylvania

Pre-Employment Background Check With Consent For Future Checks



how to use included variable from file with jinja2 template and with_items



2019 Community Moderator Electionfor loop in jinja2Bash script and yml file outputHow to modify sudoers file with ansible?How do I open a file with ansible-vault edit from inside vim?Taking register value and using it later as variableHow to make playbook idempotent with raw module?separator value from fact variable in ansibleHow to save ansible stdout.lines to a file is in list formatreplace specific line in file with ansibleHow do i store a variable value to a file in new lines on ansibleAnsible Playbook: Get value from variable










0















I am having an error where the fields of my variable are not being detected when trying to build a configuration using a jinja2 template. This is to sync Linux repositories to yum and apt based systems from a golden source using ansible. Each repository configuration would go into a different file and the task updated with the variable name. Base system configs should be able to be put in one file using multiple uses of "-" then a list of attributes.



I have reviewed:



for loop in jinja2



https://omarkhawaja.com/accessing-ansible-variables-with-jinja2-loops/



https://stackoverflow.com/questions/25418158/templating-multiple-yum-repo-files-with-ansible-template-module



as well as others that are less relevant to what I am doing.



var file:



---
repo:
- name: google_chrome
async: 1
url: http://dl.google.com/linux/chrome/rpm/stable/x86_6
...


include var task:



- name: Include var into the 'chrome' variable.
include_vars:
file: google_chrome_repo.yaml
name: chrome


task to use template module:



- name: generate config for Centos
template:
src: yum_template.j2
dest: "/etc/yum.repos.d/ item .repo"
backup: yes
with_items:
- chrome
when:
- ansible_distribution == 'CentOS'


template:



% for i in item %
[ i.name ]
async = i.async
baseurl = i.url
enabled = i.repo_enable
enablegroups = i.pkggrp_enable
failovermethod = i.ha_method
gpgkey = i.gpgkey_url
http_caching = i.http_caching
keepcache = i.keepcache
metadata_expire = i.metadata_expire
mirrorlist = i.mirrorlist
mirrorlist_expire = i.mirrorlist_expire
name = i.descrip
protect = i.protect
proxy = i.proxy_config
proxy_password = i.proxy_username
proxy_username = i.proxy_password
repo_gpgcheck = i.repo_gpgcheck
retries = i.repo_retry_count
s3_enabled = i.s3_enabled
sslverify = i.ssl_verify
timeout = i.timeout
% endfor %


error:



failed: [192.168.33.31] (item=chrome) => "changed": false, "item": "chrome", "msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'name'"


whichever attribute in role is first called by the jinja2 template will fail in this way. If I change the following so name isn't referenced and "i.name" becomes just "chrome" it will fail on async



I can see the variable is imported



ok: [192.168.33.31] => "ansible_facts": "chrome": "repo": ["async": 1, "descrip": "Google Chrome Repository", "gpgkey_url": "https://dl.google.com/linux/linux_signing_key.pub", "ha_method": "roundrobin", "http_caching": 1, "keepcache": 1, "metadata_expire": 21600, "mirrorlist": null, "mirrorlist_expire": 21600, "name": "google_chrome", "pkggrp_enable": 1, "protect": 0, "proxy_config": "__None__", "proxy_password": null, "proxy_username": null, "repo_enable": 1, "repo_gpgcheck": 1, "repo_retry_count": 10, "s3_enabled": 0, "ssl_verify": 1, "timeout": 1, "url": "http://dl.google.com/linux/chrome/rpm/stable/x86_6"], "ansible_included_var_files": ["/var/lib/awx/projects/_6__trowe/playbooks/roles/Manage_Linux_Repos/vars/google_chrome_repo.yaml"], "changed": false


I do see it says "unicode" variable where I would expect it to be a dict. I have also tried with_dict and the error says that the variable is not a dictionary. However if I structure the variable file without "repo:", it will error saying it was not passed a dictionary object...










share|improve this question









New contributor




Hiker86 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    0















    I am having an error where the fields of my variable are not being detected when trying to build a configuration using a jinja2 template. This is to sync Linux repositories to yum and apt based systems from a golden source using ansible. Each repository configuration would go into a different file and the task updated with the variable name. Base system configs should be able to be put in one file using multiple uses of "-" then a list of attributes.



    I have reviewed:



    for loop in jinja2



    https://omarkhawaja.com/accessing-ansible-variables-with-jinja2-loops/



    https://stackoverflow.com/questions/25418158/templating-multiple-yum-repo-files-with-ansible-template-module



    as well as others that are less relevant to what I am doing.



    var file:



    ---
    repo:
    - name: google_chrome
    async: 1
    url: http://dl.google.com/linux/chrome/rpm/stable/x86_6
    ...


    include var task:



    - name: Include var into the 'chrome' variable.
    include_vars:
    file: google_chrome_repo.yaml
    name: chrome


    task to use template module:



    - name: generate config for Centos
    template:
    src: yum_template.j2
    dest: "/etc/yum.repos.d/ item .repo"
    backup: yes
    with_items:
    - chrome
    when:
    - ansible_distribution == 'CentOS'


    template:



    % for i in item %
    [ i.name ]
    async = i.async
    baseurl = i.url
    enabled = i.repo_enable
    enablegroups = i.pkggrp_enable
    failovermethod = i.ha_method
    gpgkey = i.gpgkey_url
    http_caching = i.http_caching
    keepcache = i.keepcache
    metadata_expire = i.metadata_expire
    mirrorlist = i.mirrorlist
    mirrorlist_expire = i.mirrorlist_expire
    name = i.descrip
    protect = i.protect
    proxy = i.proxy_config
    proxy_password = i.proxy_username
    proxy_username = i.proxy_password
    repo_gpgcheck = i.repo_gpgcheck
    retries = i.repo_retry_count
    s3_enabled = i.s3_enabled
    sslverify = i.ssl_verify
    timeout = i.timeout
    % endfor %


    error:



    failed: [192.168.33.31] (item=chrome) => "changed": false, "item": "chrome", "msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'name'"


    whichever attribute in role is first called by the jinja2 template will fail in this way. If I change the following so name isn't referenced and "i.name" becomes just "chrome" it will fail on async



    I can see the variable is imported



    ok: [192.168.33.31] => "ansible_facts": "chrome": "repo": ["async": 1, "descrip": "Google Chrome Repository", "gpgkey_url": "https://dl.google.com/linux/linux_signing_key.pub", "ha_method": "roundrobin", "http_caching": 1, "keepcache": 1, "metadata_expire": 21600, "mirrorlist": null, "mirrorlist_expire": 21600, "name": "google_chrome", "pkggrp_enable": 1, "protect": 0, "proxy_config": "__None__", "proxy_password": null, "proxy_username": null, "repo_enable": 1, "repo_gpgcheck": 1, "repo_retry_count": 10, "s3_enabled": 0, "ssl_verify": 1, "timeout": 1, "url": "http://dl.google.com/linux/chrome/rpm/stable/x86_6"], "ansible_included_var_files": ["/var/lib/awx/projects/_6__trowe/playbooks/roles/Manage_Linux_Repos/vars/google_chrome_repo.yaml"], "changed": false


    I do see it says "unicode" variable where I would expect it to be a dict. I have also tried with_dict and the error says that the variable is not a dictionary. However if I structure the variable file without "repo:", it will error saying it was not passed a dictionary object...










    share|improve this question









    New contributor




    Hiker86 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      0












      0








      0








      I am having an error where the fields of my variable are not being detected when trying to build a configuration using a jinja2 template. This is to sync Linux repositories to yum and apt based systems from a golden source using ansible. Each repository configuration would go into a different file and the task updated with the variable name. Base system configs should be able to be put in one file using multiple uses of "-" then a list of attributes.



      I have reviewed:



      for loop in jinja2



      https://omarkhawaja.com/accessing-ansible-variables-with-jinja2-loops/



      https://stackoverflow.com/questions/25418158/templating-multiple-yum-repo-files-with-ansible-template-module



      as well as others that are less relevant to what I am doing.



      var file:



      ---
      repo:
      - name: google_chrome
      async: 1
      url: http://dl.google.com/linux/chrome/rpm/stable/x86_6
      ...


      include var task:



      - name: Include var into the 'chrome' variable.
      include_vars:
      file: google_chrome_repo.yaml
      name: chrome


      task to use template module:



      - name: generate config for Centos
      template:
      src: yum_template.j2
      dest: "/etc/yum.repos.d/ item .repo"
      backup: yes
      with_items:
      - chrome
      when:
      - ansible_distribution == 'CentOS'


      template:



      % for i in item %
      [ i.name ]
      async = i.async
      baseurl = i.url
      enabled = i.repo_enable
      enablegroups = i.pkggrp_enable
      failovermethod = i.ha_method
      gpgkey = i.gpgkey_url
      http_caching = i.http_caching
      keepcache = i.keepcache
      metadata_expire = i.metadata_expire
      mirrorlist = i.mirrorlist
      mirrorlist_expire = i.mirrorlist_expire
      name = i.descrip
      protect = i.protect
      proxy = i.proxy_config
      proxy_password = i.proxy_username
      proxy_username = i.proxy_password
      repo_gpgcheck = i.repo_gpgcheck
      retries = i.repo_retry_count
      s3_enabled = i.s3_enabled
      sslverify = i.ssl_verify
      timeout = i.timeout
      % endfor %


      error:



      failed: [192.168.33.31] (item=chrome) => "changed": false, "item": "chrome", "msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'name'"


      whichever attribute in role is first called by the jinja2 template will fail in this way. If I change the following so name isn't referenced and "i.name" becomes just "chrome" it will fail on async



      I can see the variable is imported



      ok: [192.168.33.31] => "ansible_facts": "chrome": "repo": ["async": 1, "descrip": "Google Chrome Repository", "gpgkey_url": "https://dl.google.com/linux/linux_signing_key.pub", "ha_method": "roundrobin", "http_caching": 1, "keepcache": 1, "metadata_expire": 21600, "mirrorlist": null, "mirrorlist_expire": 21600, "name": "google_chrome", "pkggrp_enable": 1, "protect": 0, "proxy_config": "__None__", "proxy_password": null, "proxy_username": null, "repo_enable": 1, "repo_gpgcheck": 1, "repo_retry_count": 10, "s3_enabled": 0, "ssl_verify": 1, "timeout": 1, "url": "http://dl.google.com/linux/chrome/rpm/stable/x86_6"], "ansible_included_var_files": ["/var/lib/awx/projects/_6__trowe/playbooks/roles/Manage_Linux_Repos/vars/google_chrome_repo.yaml"], "changed": false


      I do see it says "unicode" variable where I would expect it to be a dict. I have also tried with_dict and the error says that the variable is not a dictionary. However if I structure the variable file without "repo:", it will error saying it was not passed a dictionary object...










      share|improve this question









      New contributor




      Hiker86 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I am having an error where the fields of my variable are not being detected when trying to build a configuration using a jinja2 template. This is to sync Linux repositories to yum and apt based systems from a golden source using ansible. Each repository configuration would go into a different file and the task updated with the variable name. Base system configs should be able to be put in one file using multiple uses of "-" then a list of attributes.



      I have reviewed:



      for loop in jinja2



      https://omarkhawaja.com/accessing-ansible-variables-with-jinja2-loops/



      https://stackoverflow.com/questions/25418158/templating-multiple-yum-repo-files-with-ansible-template-module



      as well as others that are less relevant to what I am doing.



      var file:



      ---
      repo:
      - name: google_chrome
      async: 1
      url: http://dl.google.com/linux/chrome/rpm/stable/x86_6
      ...


      include var task:



      - name: Include var into the 'chrome' variable.
      include_vars:
      file: google_chrome_repo.yaml
      name: chrome


      task to use template module:



      - name: generate config for Centos
      template:
      src: yum_template.j2
      dest: "/etc/yum.repos.d/ item .repo"
      backup: yes
      with_items:
      - chrome
      when:
      - ansible_distribution == 'CentOS'


      template:



      % for i in item %
      [ i.name ]
      async = i.async
      baseurl = i.url
      enabled = i.repo_enable
      enablegroups = i.pkggrp_enable
      failovermethod = i.ha_method
      gpgkey = i.gpgkey_url
      http_caching = i.http_caching
      keepcache = i.keepcache
      metadata_expire = i.metadata_expire
      mirrorlist = i.mirrorlist
      mirrorlist_expire = i.mirrorlist_expire
      name = i.descrip
      protect = i.protect
      proxy = i.proxy_config
      proxy_password = i.proxy_username
      proxy_username = i.proxy_password
      repo_gpgcheck = i.repo_gpgcheck
      retries = i.repo_retry_count
      s3_enabled = i.s3_enabled
      sslverify = i.ssl_verify
      timeout = i.timeout
      % endfor %


      error:



      failed: [192.168.33.31] (item=chrome) => "changed": false, "item": "chrome", "msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'name'"


      whichever attribute in role is first called by the jinja2 template will fail in this way. If I change the following so name isn't referenced and "i.name" becomes just "chrome" it will fail on async



      I can see the variable is imported



      ok: [192.168.33.31] => "ansible_facts": "chrome": "repo": ["async": 1, "descrip": "Google Chrome Repository", "gpgkey_url": "https://dl.google.com/linux/linux_signing_key.pub", "ha_method": "roundrobin", "http_caching": 1, "keepcache": 1, "metadata_expire": 21600, "mirrorlist": null, "mirrorlist_expire": 21600, "name": "google_chrome", "pkggrp_enable": 1, "protect": 0, "proxy_config": "__None__", "proxy_password": null, "proxy_username": null, "repo_enable": 1, "repo_gpgcheck": 1, "repo_retry_count": 10, "s3_enabled": 0, "ssl_verify": 1, "timeout": 1, "url": "http://dl.google.com/linux/chrome/rpm/stable/x86_6"], "ansible_included_var_files": ["/var/lib/awx/projects/_6__trowe/playbooks/roles/Manage_Linux_Repos/vars/google_chrome_repo.yaml"], "changed": false


      I do see it says "unicode" variable where I would expect it to be a dict. I have also tried with_dict and the error says that the variable is not a dictionary. However if I structure the variable file without "repo:", it will error saying it was not passed a dictionary object...







      ansible






      share|improve this question









      New contributor




      Hiker86 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Hiker86 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 9 hours ago









      Rui F Ribeiro

      41.5k1483141




      41.5k1483141






      New contributor




      Hiker86 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 14 hours ago









      Hiker86Hiker86

      1




      1




      New contributor




      Hiker86 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Hiker86 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Hiker86 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Hiker86 is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507021%2fhow-to-use-included-variable-from-file-with-jinja2-template-and-with-items%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Hiker86 is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          Hiker86 is a new contributor. Be nice, and check out our Code of Conduct.












          Hiker86 is a new contributor. Be nice, and check out our Code of Conduct.











          Hiker86 is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507021%2fhow-to-use-included-variable-from-file-with-jinja2-template-and-with-items%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

          Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

          Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.