Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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.
    matrixbot
    @matrixbot
    dziendobry Hi. what would be the best way to split a list in smaller chuncks using ansible? I have a list of servers which I use to execute async tasks. The problem is that the computer gets overload and now Im trying to find a way to send only 5 tasks at a time. Is it possible with ansible?
    ecaepp
    @ecaepp
    how would I respond to dziendobry issue from matrixbot?
    matrixbot
    @matrixbot
    Michael S. Moody If I understand what you mean, there's a concurrent task limit setting that's set in ansible.cfg
    matrixbot
    @matrixbot
    dziendobry Michael S. Moody: :D. I believe changing that value could help me. I will performe some tests. Thanks
    reneeshk
    @reneeshk
    Help!. How do I run an ad-hoc command using the raw module?
    ecaepp
    @ecaepp
    @reneeshk should just be ansible -m raw -a "cat my_file" my_host, and just as a side note Ansible recommends using the command or shell module when possible.
    reneeshk
    @reneeshk
    @ecaepp Thank you.
    Ahmed Shabana
    @AhmedShabana2_twitter

    Dears , I write down a module , but for reason that I donot know it did not ever run!!
    it just print the name tag with no real execution
    [root@ip-192-168-81-181 ansible]# ansible-playbook local.site.yml -vvv
    ansible-playbook 2.8.6
    config file = None
    configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
    ansible python module location = /usr/lib/python2.7/site-packages/ansible
    executable location = /bin/ansible-playbook
    python version = 2.7.16 (default, Jul 19 2019, 23:05:17) [GCC 7.3.1 20180712 (Red Hat 7.3.1-6)]
    No config file found; using defaults
    host_list declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
    Skipping due to inventory source not existing or not being readable by the current user
    script declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
    auto declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
    Skipping due to inventory source not existing or not being readable by the current user
    yaml declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
    Skipping due to inventory source not existing or not being readable by the current user
    ini declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
    Skipping due to inventory source not existing or not being readable by the current user
    toml declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
    [WARNING]: No inventory was parsed, only implicit localhost is available

    [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

    PLAYBOOK: local.site.yml **
    1 plays in local.site.yml

    PLAY [Preparing localhost] **
    META: ran handlers

    TASK [Trying to include role] *

    TASK [Just for debug] *
    task path: /usr/local/src/ansible/local.site.yml:15
    ok: [localhost] => {
    "msg": "???"
    }
    META: ran handlers
    META: ran handlers

    PLAY RECAP **
    localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0


    And below is my directory structure and my playbook


    [root@ip-192-168-81-181 ansible]# tree
    .
    ├── local
    │ ├── host_vars
    │ │ └── localhost
    │ └── vars
    │ └── cfg.yml
    ├── local.site.yml
    ├── production
    │ └── host_vars
    ├── roles
    │ └── sdpApp
    │ ├── common
    │ │ └── tasks
    │ │ └── main.yml
    │ └── default
    │ ├── main.yml
    │ └── requirements.yml
    └── test.yml

    10 directories, 7 files

    [root@ip-192-168-81-181 ansible]# cat local.site.yml

    • name: Preparing localhost

      hosts: localhost
      connection: local
      become: yes
      gather_facts: False
      roles:

          - sdpApp

      tasks:

          - name: "Trying to include role"
            include_role:
                    name: sdpApp
      
          - name: "Just for debug"
            debug:
                    msg: "???"
    As you can see that
    TASK [Trying to include role] *
    is empty at debug and not executed ever ?!
    Ahmed Shabana
    @AhmedShabana2_twitter


    Let me write down the issue again with better markdown

    The issue is -> I write a module dummy and want to run it from inside my playbook

    my directory structure looks like :

    .
    ├── local
    │ ├── host_vars
    │ │ └── localhost
    │ └── vars
    │ └── cfg.yml
    ├── local.site.yml
    ├── production
    │ └── host_vars
    ├── roles
    │ └── sdpApp
    │ ├── common
    │ │ └── tasks
    │ │ └── main.yml
    │ └── default
    │ ├── main.yml
    │ └── requirements.yml

    └── test.yml

    I try to execute the playbook with this command :

    ansible-playbook local.site.yml -vvv

    content of local.site.yml is

    ---
    - name: Preparing localhost
    
      hosts: localhost
      connection: local
      become: yes
      gather_facts: False
      roles:
          - sdpApp
      tasks:
          - name: "Trying to include role"
            include_role:
                    name: sdpApp
    
          - name: "Just for debug"
            debug:
                    msg: "???"

    content of cat roles/sdpApp/common/tasks/main.yml

    tasks:
        - debugxx:
                msg: "Just for debug that we are \
          inside roles/sdpApp/common/tasks/default.yml"
        - debug:
                msg: "Env var cfg.variable1 = {{ cfg.variable1 }}"
        - name: Create a tmp file
          file: path=/tmp/file.delmexxxxx

    The problem is that my role does not execute

    [root@ip-192-168-81-181 ansible]# ansible-playbook local.site.yml -vvv
    ansible-playbook 2.8.6
    config file = None
    configured module search path = 
    [u'/root/.ansible/plugins/modules', 
    u'/usr/share/ansible/plugins/modules']
    ansible python module location = 
    /usr/lib/python2.7/site-packages/ansible
    executable location = /bin/ansible-playbook
    python version = 2.7.16 (default, Jul 19 2019, 
    23:05:17) [GCC 7.3.1 20180712 (Red Hat 7.3.1-6)]
    No config file found; using defaults
    host_list declined parsing /etc/ansible/hosts as 
    it did not pass it's verify_file() method
    Skipping due to inventory source not existing or 
    not being readable by the current user 
    script declined parsing /etc/ansible/hosts as it 
    did not pass it's verify_file() method
    auto declined parsing /etc/ansible/hosts as it 
    did not pass it's verify_file() method
    Skipping due to inventory source not existing or 
    not being readable by the current user
    yaml declined parsing /etc/ansible/hosts as it 
    did not pass it's verify_file() method
    Skipping due to inventory source not existing or 
    not being readable by the current user
    ini declined parsing /etc/ansible/hosts as it did 
    not pass it's verify_file() method
    Skipping due to inventory source not existing or 
    not being readable by the current user
    toml declined parsing /etc/ansible/hosts as it 
    did not pass it's verify_file() method
    [WARNING]: No inventory was parsed, only implicit 
    localhost is available
    
    [WARNING]: provided hosts list is empty, only 
    localhost is available. Note that the implicit 
    localhost does not match 'all'
    PLAYBOOK: local.site.yml 
    
    
    
     ***********************
     1 plays in local.site.yml
    
    PLAY [Preparing localhost] ************************************************************************************************************************************
    META: ran handlers
    
    TASK [Trying to include role] *********************************************************************************************************************************
    task path: /usr/local/src/ansible/local.site.yml:11
    
    TASK [Just for debug] *****************************************************************************************************************************************
    task path: /usr/local/src/ansible/local.site.yml:15
    ok: [localhost] => {
    "msg": "???"
    }
    META: ran handlers
    META: ran handlers
    
    PLAY RECAP **************************************************************************************************************
    Ahmed Shabana
    @AhmedShabana2_twitter
    anyone can advice ?
    Nicholas Amorim
    @nicholasamorim
    Shot in the dark but probably because you have a common folder between the top-level role folder and tasks/main.yaml
    Jay Carlson
    @nopdotcom
    I can't read the directory hierarchy. Could you run find . -print?
    Larry Brigman
    @lbrigman124
    I agree. That common dir between the role name and the tasks is not a standard structure If you were trying to have common roles, put the roles in common and add that path to your role search path. I'm kind of surprised that you didn't get an error.
    Another thing. With the current structure of the playbook; if the role was found would be that it would be run twice. Once from roles and then from the include_role.
    Ahmed Shabana
    @AhmedShabana2_twitter
    Thank you all , thank you @nicholasamorim it was really the common folder as you mensioned .
    jasoncal108
    @jasoncal108

    Regarding aws_ec2 inventory plugin, has anyone found a way to remove the underscore that is appended to keyed_groups when looking up a tag? ie

    tag:Role -> results in _role-output

    or is there a way to rename a group?
    matrixbot
    @matrixbot
    Michael S. Moody Good afternoon. What's preferred and most stable for Ansible for managing Windows hosts? PSRP or WinRM? (I've been using WinRM, but I'm having random connectivity issues). I've managed thousands of hosts with Ansible (Linux hosts), and about a hundred Windows hosts, but it's just not being as stable as I'd expect
    zahna
    @zahna
    Is there good documentation for utilizing ansible programmatically? I'd like to utilize some facts about the local host in a standalone python script.
    ecaepp
    @ecaepp

    @zahna Ansible can be configured to cache facts in JSON/YAML files or store facts in a cahcing database such as Redis or Memcache. Once the facts have been cached you simply can read the files or query the DB with Python. See https://docs.ansible.com/ansible/latest/plugins/cache.html

    Another option would be to use Jinja templating in your Python script,but without knowing the nature or complexity of the Python script I would recommend trying the first option over this one.

    Robert Kaussow
    @xoxys
    Hi guys, is there any best practice for role naming?
    In the past I guess there were some recommendations like vendor.role_name but I can't find any information about role name conventions
    zahna
    @zahna
    @ecaepp Thanks for the info. The second option might work in my situation. I'll have to try it out. I was hoping there would be a clean way to run ansible's fact fetching methods in a standalone python script.
    John R Barker
    @gundalow
    Hi everybody. Tomorrow we will be our next "Big PR Review Day", see ansible/community#407 for info. Hope to see some of you there