by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    DiViNeCH
    @DiViNeCH
    thanks
    arogic
    @arogic
    Hi, installed ansible-lint (version 4.2.0) on my Ubuntu and my Mac, but when I run ansible-lint against a playbook it doesn’t show anything, no error, no message. Does anybody else experience same behaviour? Already googled, but didn’t find anything. Anything I am missing or do I need to install some dependencies which I am not aware of? Thanks for your help
    Laurent G
    @xenlo
    And with a -v flag?
    ansible-lint -v playbooks/my_little_playbook.yml
    it has to answer you at least "Examining playbooks/my_little_playbook.yml of type playbook"
    arogic
    @arogic
    Hi @xenlo I ran ansible-lint against role tasks which doesn’t seem to work. Wen I run it against a playbook it works.
    @xenlo, when I run ansible-lint -v main.yml I get Examining main.yml of type playbook
    Laurent G
    @xenlo
    So it means it did found any lint error
    if you want you can double check and run a echo $? directly after and if the answer is 0 it means the previous command (ansible-lint in your case) run successfully
    arogic
    @arogic
    Thanks @xenlo, however wondering why it wouldn’t check individual role tasks
    Laurent G
    @xenlo
    @arogic, ah if in your playbooks/my_little_playbook.yml you have a roles: section, it should walk through the tasks of all roles referenced
    arogic
    @arogic
    Hi, when running ansible-playbook in a script and a task fails I still get exit code zero, I expected to get an non-zero exit code so that my CI fails accordingly
    arogic
    @arogic
    ignore my previous question, I got it solved
    DiViNeCH
    @DiViNeCH
    ---
    
    - hosts: hostname 
      gather_facts: no
      tasks:
        - name: Ansible multiple replace example
          replace:
            path: "{{ item.path }}"
            regexp: "{{ item.search_uid }}"
            replace: "{{ item.replace_uid }}"
          with_items:
            - { path: '{{ file_path }}', search_uid: ' useridshort', replace_uid: 'useridshort userid.long'}

    useridshort
    and
    userid.long
    is only normal text. Like surename.name or userdi for ex myuserid

    I'd like to add to this only uf userid.long is not present.

    - { path: '{{ file_path }}', search_uid: ' useridshort', replace_uid: 'useridshort userid.long'}

    something like:
    when != userid.long

    for ex:

    dot it if
    shortname is pressent

    matrixbot
    @matrixbot

    friesennerd > <@gitter_divinech:matrix.org> ```


    • hosts: hostname
      gather_facts: no
      tasks:
      • name: Ansible multiple replace example
        replace:
        path: "{{ item.path }}"
        regexp: "{{ item.search_uid }}"
        replace: "{{ item.replace_uid }}"
        with_items:
        • { path: '{{ file_path }}', search_uid: ' useridshort', replace_uid: 'useridshort userid.long'}
          ```

    useridshort
    and
    userid.long
    is only normal text. Like surename.name or userdi for ex myuserid

    I'd like to add to this only uf userid.long is not present.

    - { path: '{{ file_path }}', search_uid: ' useridshort', replace_uid: 'useridshort userid.long'}

    something like:
    when != userid.long

    for ex:

    dot it if
    shortname is pressent

    when: userid.long is not defined

    DiViNeCH
    @DiViNeCH
    Hmm... males sense but dosen't work
    ---
    # playbook file for change-apache-conf-ldap-users.yml
    # Sucht User und ersetzt diesen in der jeweilen Datei
    
    - hosts: tsrvma298 
      gather_facts: no
      tasks:
        - name: Replace single User ID (test)with Single UserID and FUll-User-ID
    # User ID  = singleid This is only text --> the user name
    # Full ID = full.id   This is only text --> the full username  
          replace:
            path: "{{ item.path }}"
            regexp: "{{ item.search_uid }}"
            replace: "{{ item.replace_uid }}"
          with_items:
            - { path: '{{ file_path }}', search_uid: ' singleid', replace_uid: ' singleid singleid', when: full.id is not defined }
    
    # That happens after execution:
    # This is how the file lookfed before ansible:  Require aaa bbb singleid ccc  ddd eee fff ggg full.id
    # This is how the file lookfed after ansible:   Require aaa bbb singleid full.id ccc  ddd eee fff ggg full.id
    # Tha last full.id is wrong. It should it only add it it wasn't present before.
    DiViNeCH
    @DiViNeCH

    https://docs.ansible.com/ansible/2.4/playbooks_loops.html

    This didn't help me but it's interesting and therefore I'd like to share.

    DiViNeCH
    @DiViNeCH

    I changed it to this:

    # keep in mind, that full.id and singleid is only text!
          with_items:
            - { path: '{{ file_path }}', search_uid: ' singleid', replace_uid: ' singleid full.id', check_if_there: 'full.id', when: check_if_there is not defined }

    Still the same problem.

    DiViNeCH
    @DiViNeCH

    Thats the outbut, this might help:

    TASK [Ansible multiple replace example] ************************************************************************************************************************************************************************ changed: [theservername] => (item={u'search_uid': u' singleid ', u'path': u'/home/singleid /icinga.conf', u'when': u'check_if_there is not defined', u'replace_uid': u' singleid full.id', u'check_if_there': u'full.id'}) => {"changed": true, "item": {"check_if_there": "full.id", "path": "/home/singleid /icinga.conf", "replace_uid": " singleid full.id", "search_uid": " singleid ", "when": "check_if_there is not defined"}, "msg": "2 replacements made"}

    2 replacements made, but onle one would be needed..... two is wrong. 🤷‍♂️
    Sandeep Anand
    @sananand007

    ./ec2.py --list

    This works and lists all the information needed and I am able to list all the relevant information for the ec2 instance, but the ping below does not go through ? Any ideas how I can setup my /etc/ansible/hosts file to get the below running as well .

    I do not have bare metal hosts, so I am going to use a ubuntu EC2 instance

    ansible -i ec2.py all -m ping
    
    
    
    <ip> | UNREACHABLE! => {
    
        "changed": false,
    
        "msg": "Failed to connect to the host via ssh: Permission denied (publickey).",
    
        "unreachable": true
    
    }
    Lumina Dsouza
    @reeshu13489
    Check if the username trying to connect is correct ssh username@hostname
    Become user in other words
    ansible -i ec2.py all -m ping -u <your username here>
    Hope this helps
    Sandeep Anand
    @sananand007
    @reeshu13489 tnx for the reply.. but this is not going through
    I can ssh as below to my ubuntu instance successfully, but what is the username here, ubuntu does not work ..
    $ ssh -i somekey.pem ubuntu@ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com
    Sandeep Anand
    @sananand007

    @reeshu13489 ok I take that back .. tnx again .. It does work with ubuntu
    THe thing is the ip is a dynamic public name as it is aws .. so I had to do the below (which not sure why was it required yet)

    $ exec ssh-agent bash
    $ ssh-add somekey.pem

    and reconnect using $ ssh -i somekey.pem ubuntu@ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com

    <ip> | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python3"
        },
        "changed": false,
        "invocation": {
            "module_args": {
                "data": "pong"
            }
        },
        "ping": "pong"
    }
    though as this is a dynamic inventory .. need to find a better way rather doing these steps again ..
    Lumina Dsouza
    @reeshu13489
    Wow that’s a good lesson to me @sananand007 , I will also try to figure out and share if I get better solutions and please do share if you find one
    Sandeep Anand
    @sananand007
    sg!
    Lumina Dsouza
    @reeshu13489
    I tried to create ec2 instance with key pair and executed ansible -I ec2.py all -m ping -u ec2-user —private-key keyvaluepair.pem without any additional step works for me
    Sandeep Anand
    @sananand007
    yes this works tnx
    ansible -i devops-starter/ansible/inventory/ec2.py all -m ping -u ubuntu --private-key somekey.pem
    do not have to the extra steps ..
    DiViNeCH
    @DiViNeCH
    @matrixbot I can't see what's wrong. It's syntactical correct, right?
    DiViNeCH
    @DiViNeCH

    Before:
    user1 user2 user3 user4 user2.name
    After:
    user1 user2 user2.name user3 user4 user2.name

    I guess he get's a hit and edits both.

    DiViNeCH
    @DiViNeCH
    I fixed it by addung tow lines. The first one remoces user2.name first. More code, but it works 🤷‍♀️
    matrixbot
    @matrixbot
    illusive_evil hello, i am new to ansible..want to know to print the gathered facts from fortios_facts module?
    arogic
    @arogic
    Hi, is it a good idea to run yamllint over playbooks and role tasks? I am currently running ansible-lint and yamllint agaist the playbooks and roles.
    DiViNeCH
    @DiViNeCH
    ---
    - hosts: all
      gather_facts: no
      tasks:
        - name: "Edit httpd.conf Datei"
          replace:
            path: "{{ item.path }}"
            regexp: "{{ item.search_uid }}"
            replace: "{{ item.replace_uid }}"
    #        Delete old if there:
            - { path: '{{ file_path }}', search_uid: 'firstname.lastname', replace_uid: '', check_if_there: ' firstname.lastname', when: check_if_there is not defined }
    #        Add new:
            - { path: '{{ file_path }}', search_uid: ' userid', replace_uid: ' userid firstname.lastname', check_if_there: 'firstname.lastname', when: check_if_there is not defined }

    After edit the file loos like this
    user1 firstname1.lasname1 user2 firstname2.lasname2 user3 firstname3.lasname3
    instead of:
    user1 firstname1.lasname1 user2 firstname2.lasname2 user3 firstname3.lasname3
    There is one blank to much between each edit.

    I guess it's because of:
    replace_uid: ''

    ecaepp
    @ecaepp

    Morning @DiViNeCH, have you considered using a template to manage the httpd.conf file? I generally find using modules such as replace, lineinfile, and blockinfile to modify large chunks of conf file is error prone and difficult to troubleshoot.

    Using a template could simplify the task as you would just overwrite the current config with the updated one by just simply provide your users as a variable that you would iterate over.

    Example

    defaults/main.yml

    users:
      - name: user1
        fname: uf1
        lname: ul1
        uid: 11111
      - name: user2
        fname: uf2
        lname: ul2
        uid: 22222

    templates/my_config.conf.j2 (config template)

    {% if users is defined and users != None %}
    {% for u in users %}
    {{ u.name }}, {{ u.fname }}, {{ u.lname }}, {{ u.uid }}
    {% endfor %}
    {% endif %}

    tasks/main.yml

    - name: Generate config from template
      template:
        src: templates/my_config.conf.j2
        dest: /my/config/path/on/target
        owner: my_user
        group: my_group
        mode: 0640

    Output

    [root@instance ~]# cat test.conf 
    user1, uf1, ul1, 11111
    user2, uf2, ul2, 22222
    matrixbot
    @matrixbot
    zem Uhm I have an interesting Problem: My Playbooks are getting stuck when I tried to run them on ansible >= 2.9.7 it is working with 2.9.3 are there any known performance issues with the lookup of Jinja2 Inventories?
    zem It is definately a performance issue as the steps are taking +20 min till they do anything as soon as they access an inventory variable that does some j2 mapping.
    matrixbot
    @matrixbot
    zem ah there is a bug open. :)
    Nathan Davis
    @asteroidDavis
    Morning. Ive started using the free strategy and I'm concerned about the ordered execution of plays. If i have the following playbook structure will the tasks from import_playbook always run after the role.
    - hosts: webservers
      strategy: free
      serial: 4
      roles:
        - application_backup
    - name: check backup statistics on all webservers
      import_playbook: test_backup.yml
    Also is there any documentation for ordering of plays using various strategies or scope of strategies?
    ecaepp
    @ecaepp
    Morning @asteroidDavis, While I havn't messed around to much yet with strategies, but can say that shouldn't be any change to the way the play/playbook run against your targets since Ansible is powered by Python which runs top down.
    Roman
    @invizus

    Have a question about aws_ec2 inventory. https://docs.ansible.com/ansible/latest/plugins/inventory/aws_ec2.html

    Some of my instances are available only internally, not public. I would like to use hostnamesparameter.

    hostnames:
      - dns-name
      - private-ip-address

    I think ansible uses hostname in order it discovers them. But if it fails to connect via dns-name, it seems ansible does not retry private-ip-address.