Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use #254

Open
asobeeh opened this issue Apr 28, 2021 · 1 comment
Open

how to use #254

asobeeh opened this issue Apr 28, 2021 · 1 comment

Comments

@asobeeh
Copy link

asobeeh commented Apr 28, 2021

sorry about that, but I am new with ansible and I want to call this playbook in my playbook as a role.
and I want to know how to use this playbook, were to define the hosts, what should I do,
can you please define a how-to, to explain in steps how to run it and where is the values should I change and where to change,
and for the replica how to enable it, and how to make it a single deployment or replica deployment with attribute
I know that it may be a clear thing but sorry for that.

can you please help me with this

I tried the below to call it a role and pass the var from my playbook but it give me the below error

- hosts: all
  tasks:
    - name: "get facts about ip addresses"
      setup:
        filter: ansible_default_ipv4
    - name: "set mongodb_replication_params variable"
      set_fact:
        mongodb_replication_params:
          - host_name: "{{ hostvars[item]['ansible_default_ipv4']['address'] }}"
            host_type: "{{ replica if 'mongodb-replica' in group_names else arbiter }}"
      with_items:
        - "{{ groups['mongodb-replica'] }}"
        - "{{ groups['mongodb-arbiter'] }}"
      debug: msg="echo"
  roles:
    - ansible-role-mongodb
    ERROR! conflicting action statements: set_fact, debug

The error appears to be in '/root/newmongo.yaml': line 7, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

        filter: ansible_default_ipv4
    - name: "set mongodb_replication_params variable"
      ^ here

I tried to use the below also,

- hosts: all
  tasks:
    - name: determine which ethernet interface holds the ip we want to use in mongo
      set_fact:
        eth_interface: "ansible_eth1"
      when: stage == "development"
    - name: determine which ethernet interface holds the ip we want to use in mongo
      set_fact:
        eth_interface: "ansible_eth0"
      when: stage != "development"
    - name: determine who is the master
      set_fact:
        mongodb_masternode: "{{ groups['mongodb-datastore'][0] }}"
    - name: determine the master ip
      set_fact:
        mongodb_masternode_ip: "{{ hostvars[mongodb_masternode][eth_interface]['ipv4']['address'] }}"
    - name: echo mongodb_masternode ip
      debug: msg={{ mongodb_masternode_ip }}
    - name: determine own ip
      set_fact:
        own_ip: "{{ ansible_eth1.ipv4.address }}"
      when: stage == "development"
    - name: determine own ip
      set_fact:
        own_ip: "{{ ansible_eth0.ipv4.address }}"
      when: stage != "development"
    - name: echo my ip
      debug: msg={{ own_ip }}
    - name: test if this machine is not the master
      set_fact:
        mongodb_master: false
      when: mongodb_masternode_ip != own_ip
    - name: test if this machine is the master
      set_fact:
        mongodb_master: true
      when: mongodb_masternode_ip == own_ip

    - name: Build replication json config
      set_fact:
        replication: "{{ lookup('template', 'mongodb_replication_params.j2') }}"
        # note that we build a _string_ here containing json, not a json object
      vars:
        hosts: "{{ groups['mongodb-datastore'] + groups['mongodb-arbiter'] }}"
    - name: echo replication
      debug: msg={{ replication }}

    - name: Convert replication json to an ansible variable mongodb_replication_params
      set_fact:
        mongodb_replication_params: "{{ replication|from_json }}"

    - name: echo mongodb_replication_params
      debug: msg={{ mongodb_replication_params }}
  roles:
    - ansible-role-mongodb
it gives me the below error
TASK [determine which ethernet interface holds the ip we want to use in mongo] *******************************************************
fatal: [192.168.1.46]: FAILED! => {"msg": "The conditional check 'stage == \"development\"' failed. The error was: error while evaluating conditional (stage == \"development\"): 'stage' is undefined\n\nThe error appears to be in '/root/mongo.yaml': line 3, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  tasks:\n    - name: determine which ethernet interface holds the ip we want to use in mongo\n      ^ here\n"}
@joe-speedboat
Copy link

Hi, I was first not able to get replication working.
If you look closer, you will see it is a json object in a list

Check the example below which is working for ALMA8 with a 3 node cluster: test01-03

- hosts: mongo
  gather_facts: yes
  vars:
    mongodb_net_bindip: "127.0.0.1,{{ ansible_default_ipv4.address }}"
    mongodb_storage_dbpath: /var/lib/mongo

    mongodb_replication_replset: rs0

    mongodb_user_admin_name: siteUserAdmin
    mongodb_user_admin_password: xxxxxx

    mongodb_root_admin_name: siteRootAdmin
    mongodb_root_admin_password: xxxxxx

    mongodb_root_backup_name: backupuser
    mongodb_root_backup_password: xxxxxx

    mongodb_security_authorization: "enabled"
    mongodb_users:
      - {
        name: graylog,
        password: xxxxxx,
        roles: readWrite,
        database: admin
    }
      - {
        name: graylog,
        password: xxxxxx,
        roles: readWrite,
        database: graylog
    }

    mongodb_login_host: test01

    mongodb_replication_params:
      - {
          host_name: test01,
          host_port: "{{ mongodb_net_port }}",
          host_type: replica,
        }
      - {
          host_name: test02,
          host_port: "{{ mongodb_net_port }}",
          host_type: replica,
        }
      - {
          host_name: test03,
          host_port: "{{ mongodb_net_port }}",
          host_type: replica,
        }


    mongodb_keyfile_content: |
      zMMfneGjUdOwBTcmdd1VZvjWWHFjhzOcECgvEygVVprbwPikijvZywhR6GCFRnnL
      XxL8rd4iT4AEuuSAiaHj7OXCyJK6h1K7UtVEPZK56MaD4fwRrLaMAn0aAVx0hUU6
      ZBRQ6g1l/nbwwxFKoX3dXu4UmzcwycYYhb3RlFxeuCftAzbd43SUEb4x7NajpFM6
      p0td0GVPyVYh1cBoxIdxWgCnarvP4mf03npeiLng037ZN6kxx9i7Yov6mjZ6v1Em
      ecHJBaybUblpi/DGr1ZI1I+IavFE0WbFQqtSHPSa3X81oz+6Y/EghIzdXyAkVSzN
      +wtzQMKolTJra/m0WQjynk/V4JXQcSZjfzhfQzpvIPaW4RTShF/TPT+hc8cMk6rQ
      8ZTcu4q9xlHdravR/GmKXpNPiqJZWvhtpZzL/O8wvbzzd9jIKCFYyQMQrhFLQa1Q
      izVjEY8N/aPLKv/opNxGVOctPK50Y+pzSB7rRWk8S3Q5MsFxN4TF5VdN0Kod3Onh
      ZZIsQ3n9lvi3Svv9stK5PTFTwMMstiaY8Wcs+J3UJDWRtDOFR/xRvgPfixC8phHC
      1FFJlEWGFKe5ivHoEcHdCoiA8a15g6WEU2IVKG7WwFdy1BJ9GdgsGj+O875aitxH
      S5KKe/zngYsX36AbyVV3IRgxhlvsgtexhfgE9i1yXUbyFMr0HIZCkEIbNKV9IxN5
      W44wtXOwkejfbVXauUYPYSUeq+VPcU0XSIz9NVJd6lhVkX0ETiCQpk6tKteWRfPQ
      3YJXHVC3myLRbXSID4O90XisJESe0i82XyWK7AzTkMO+4XXClHAqnFITbkea5Dst
      YNVKIOC7Yiyx0T4t6o8XN9YPTf18ySyzjiX2crg7YzKEbRowFyhpQ5nB+398HoWn
      MGHNUopczKplv3Rriy74GpayDWLotr13lvRHNDTDijPe76GFlIOhd6wI+olNeoFt
      LxxmU1y9YMg5RYCEKKIFbB5X0BHS

  roles:
    - role: undergreen.mongodb

Cheers Chris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants