Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    matrixbot
    @matrixbot
    wilornel Looks like there's an issue on this that was closed by ansible with no further comment? ansible/ansible#31145
    matrixbot
    @matrixbot
    wilornel Alright, I'm getting to it..
    wilornel Now, I don't know the best way to wait.
    gmldba
    @gmldba
    Im using vmware plugin and would like to use the tags for groups. I notice when I run ansible-inventory that tags are included to create groups. How can I add vm tags to the groups?
    ecaepp
    @ecaepp
    @reneeshk Going to need some more information about what you are doing and trying to accomplish.
    Terry Odom
    @TerryOdom
    Hell All. I get the following error when running a playbook but not sure how to address the colon like the error implies. Any suggestions? Thanks in advance
    The offending line appears to be:
      with_item:
        - { path: C:\ansible\apps\software\Notepad++\npp.7.5.3.Installer.x64.exe, arguments: /S }
                   ^ here
    ecaepp
    @ecaepp
    @TerryOdom try double quoting the path "C:\ansible\apps\software\Notepad++\npp.7.5.3.Installer.x64.exe"
    Terry Odom
    @TerryOdom
    ok, will try that and see. thanks
    Terry Odom
    @TerryOdom
    @ecaepp Thanks again! Just confirming your guidance worked. Much appreciated!!!
    ecaepp
    @ecaepp
    @TerryOdom No problem, if need anything else just let us know. :)
    jghal
    @jghal
    how can I put a variable interpolation inside curly braces? ie command: foobar -arg={{{myvar}}}
    the command expects the opening/closing curly brace in the argument value
    jghal
    @jghal
    blech, seems like {%raw%}{{%endraw%}{{myvar}}{%raw%}}{%endraw%} works but that's really verbose. is there any shorter syntax
    jghal
    @jghal
    {{ myvar | regex_replace('(.*)', '{\1}') }} gets the job done, seems a bit easier to read to me.
    matrixbot
    @matrixbot
    dziendobry Hi. I would like to know if someone can help me a on ansible-vault. I have a roles directory here and one role has a vars/main.yml file with the var I need to run my script and there is another file containing sensitive info call vault.yml (encrypted by ansible-vault). I would like to know how to use this vault.yml file. I first try to add it to main.yml using (include_vars: vault.yml) but it is not working (or I'm missing something)
    dziendobry I mean...I'm missing something for sure /o\
    pierremig
    @PierreOoo

    Hi I just bumped on this problem on my project, when I gather_facts, vars interpretation doesn't work anymore. This happends in ansible 2.4 and 2.8
    I'd like to keep vars interpretation when activating fact gathering.

    when gather_facts: no

    TASK [debug] **********************************************************************************************************************************
    ok: [test1-server] => (item={u'path': u'/tmp/somedir/a', u'name': u'some_name'}) => {
        "msg": {
            "name": "some_name", 
            "path": "/tmp/somedir/a"
        }

    when gather_facts: yes

    TASK [debug] **********************************************************************************************************************************
    ok: [test1-server] => (item={u'path': u'{{ dir_a }}', u'name': u'some_name'}) => {
        "msg": {
            "name": "some_name", 
            "path": "{{ dir_a }}"
        }
    }

    Playbook:

    - hosts: all
      gather_facts: yes
      vars:
        type: "dirs"
        dir_a: /tmp/somedir/a
        dirs:
          - name: "some_name"
            path: "{{ dir_a }}"
      tasks:
        - name: debug
          debug:
            msg: "{{ item }}"
          with_items:
            - "{{ vars[type]}}"
    sorry for the multiple edits
    Jay Carlson
    @nopdotcom
    Is vars a legit way of writing hostvars[inventory_hostname]?
    also I would never name a variable type :-)
    but yes, I can reproduce that
    pierremig
    @PierreOoo

    Hi Jay, here those play vars doesn't end up in hostvars[inventory_hostname].
    and yes type is a bad example for a variable
    I am using vars[] to force the interpretation of a string into a variable, which is the problem I have in my actual project.
    vars[dvars] => vars['dirs'] => [{ name: "dir_a", path: "/tmp/somedir/a"}]

    To be more precise my question is: What is the approprate way to make ansible inteprete variable that referes to other variables, and/or values(string) that referes to variables ? Espacially in this kind of nested cases !

    In this example dir_a is never interpreted through vars[dvar] (gather_facts value doesn't change anything)

    - hosts: all
      gather_facts: yes
      vars:
        dvar: "dirs"
        dir_a: /tmp/somedir/a
        dirs:
          - name: "dir_a"
            path: "{{ dir_a }}"
      tasks:
        - name: debug dvar
          debug:
            msg: "{{ dvar }}"
    
        - name: debug dirs
          debug:
            msg: "{{ dirs }}"
    
        - name: debug vars[dvar]
          debug:
            msg: "{{ vars[dvar] }}"
    
        - name: debug hostvars[inventory_hostname][dvar]
          debug:
            msg: "{{ hostvars[inventory_hostname][dvar] }}"
    TASK [debug dvar] ****************************************************************************************************************************************************************************
    ok: [test1-server] => {
        "msg": "dirs"
    }
    
    TASK [debug dirs] ****************************************************************************************************************************************************************************
    ok: [test1-server] => {
        "msg": [
            {
                "name": "dir_a", 
                "path": "/tmp/somedir/a"
            }
        ]
    }
    
    TASK [debug vars[dvar]] **********************************************************************************************************************************************************************
    ok: [test1-server] => {
        "msg": [
            {
                "name": "dir_a", 
                "path": "{{ dir_a }}"
            }
        ]
    }
    TASK [debug hostvars[inventory_hostname][dvar]] **********************************************************************************************************************************************
    fatal: [test1-server]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute u'dirs'\
    ....
    line 24, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: debug hostvars[inventory_hostname][dvar]\n      ^ here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'dict object' has no attribute u'dirs'"}
    Jay Carlson
    @nopdotcom
    I wonder where vars is documented. omit was pretty well hidden.
    pierremig
    @PierreOoo

    Things seems to work far away better with lookup('vars')...
    available from 2.5
    https://docs.ansible.com/ansible/latest/plugins/lookup/vars.html

    Thanks anyway

       - name: debug lookup('vars', dvar )
          debug:
            msg: "{{ lookup('vars', dvar )}}"
    matrixbot
    @matrixbot
    Michael S. Moody Anyone have any good solutions for a synchronize-esque behavior that works on Windows? Would the synchronize module work if rsync was installed in path on Windows?
    matrixbot
    @matrixbot
    dziendobry Is there a way to wait a task to be finish before move to the next one?
    matrixbot
    @matrixbot
    dziendobry I'm using the vmware modules to create a new vm and I woud like to move to the next step only after creation is done. Same goes to power on the VM. I would like to move on to the next step only after the OS is booted. Any tips?
    matrixbot
    @matrixbot
    dziendobry I've got it :D. Thanks!
    ecaepp
    @ecaepp

    @PierreOoo sorry for the slow response it has been busy for the last few days.

    If I am understanding correctly you have an array dirs that contains the dict name, path and want to set the variable dvar to one of the vaules in dirs, or are trying to pass the values of dirs to a module?

    Jay Carlson
    @nopdotcom
    I got tired of making role directories meta/main.yml, vars/main.yml, etc, so I wrote a tiny PR so you can write meta.yml and vars.yml. Here's nopdotcom/ansible#1. I ran some stats on all of Galaxy and of course there are huge numbers of redundant directories...
    Chris Francy
    @zoredache
    Isn't it valid to make a vars/main/foo.yml, and vars/main/blah.yml, and it will load them all
    Oh, and if you don't like making all the dirs, there is always the ansible-galaxy init command to build out the structure for you.
    Jay Carlson
    @nopdotcom
    @zoredache "Isn't it valid to make a vars/main/foo.yml"....it doesn't look like it from the documentation. Roles and Variable precedence don't seem to say so. But they also don't say that you can use .yaml and .json.
    And yeah, you can always add tooling when your environment requires boilerplate, but that's a code smell.
    Chris Francy
    @zoredache
    Pretty sure it allows vars/main to be a dir. I know it isn't documented well. I think the code is the allow_dir=true https://github.com/nopdotcom/ansible/blob/9035c49e1acad9e35375669b76075c290effd987/lib/ansible/playbook/role/__init__.py#L206
    Jay Carlson
    @nopdotcom
    Yeah. If I read the code correctly, the added code in that PR won't affect that. It's possible I should explicitly check preconditions at the top of the patch part, instead of depending on tracing through that if/then/else tree.
    matrixbot
    @matrixbot
    wilornel Oh dang, I'm having trouble doing something in Ansible
    wilornel I'd like to: run a long-running task A (poll: 0), run a task B repetitively which is the command module until A is complete.
    I'm not sure how popular is the approach above but it has been working quite well for us. The problem now is we are expanding into multiple datacenters and I'm not quite sure how to adapt the strategy above for that without duplicating files - something undesirable. Any tips?
    ecaepp
    @ecaepp
    @nicholasamorim is your inventory static, dynamic, or combo of both?
    Nicholas Amorim
    @nicholasamorim
    @ecaepp static
    Nicholas Amorim
    @nicholasamorim

    I have an inventory folder to manage multi-dc envs. I have 01_us1_hosts, 10_ca1_hosts and 99_groups. I declare hosts for each dc in the first two and in the groups one I do something like this, declaring group of groups:

    [us1:children]
    us1_database
    us1_webservers
    
    [ca1:children]
    ca1_database
    ca1_webservers

    It works very well. The problem being... I was expecting that vars set in group_vars/ca1.yaml (or us1.yaml would be resolved, but they are not - any ideas why?

    Nevermind, already solved. The group_vars folder has to move one sub-level inside the inventory folder to work. Thanks for being my rubber duck :D
    matrixbot
    @matrixbot
    wilornel heeelp!
    wilornel Apt module is not working well I think
    matrixbot
    @matrixbot
    dziendobry Hi. Any article/tutorial or help on how to do inner loops on Ansible? I have a list of servers to interate trough and I have a list of shell commands to execute in each of those servers (from a bat file) and so far I have no idea on how to implement such task on Ansible. /o\
    ecaepp
    @ecaepp
    @nicholasamorim sorry it got really busy yesterday and I wasn't able to respond. Glad you got it figured out.